简体   繁体   English

flutter 中的自定义容器形状

[英]Custom container shape in flutter

I want to make a screen like this in flutter:我想在 flutter 中制作这样的屏幕:

在此处输入图像描述

Can anyone suggest how can i make containers like this in flutter and design like this, Thanks in advance.谁能建议我如何在 flutter 中制作这样的容器并进行这样的设计,提前致谢。

You can give your containers a custom shape by using the ClipPath class.您可以使用ClipPath class 为您的容器提供自定义形状。

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: ClipPath(
            child: Container(color: Colors.red),
            clipper: MyCustomClipper(),
          ),
        ),
      ));
  }
}

class MyCustomClipper extends CustomClipper<Path> {
  @override
  Path getClip(Size size) {
    Path path = Path()
        ..lineTo(size.width, 0)
        ..lineTo(size.width, size.height/2)
        ..lineTo(size.width/2, size.height)
        ..lineTo(0, size.height)
        ..close();
      
    return path;
  }

  @override
  bool shouldReclip(CustomClipper<Path> oldClipper) => false;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM