Custom container shape in flutter

Viewed 1705

I want to make a screen like this in flutter :

enter image description here

Can anyone suggest how can i make containers like this in flutter and design like this, Thanks in advance.

1 Answers

You can give your containers a custom shape by using the 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;
}
Related