How to create a modal bottomsheet with circular corners in Flutter?

前端 未结 9 1107
时光取名叫无心
时光取名叫无心 2020-12-05 02:25

showModalBottomSheet does not provide any styling or decorations. I want to create something like the Google Tasks bottomsheet.

相关标签:
9条回答
  • 2020-12-05 02:47

    Putting together all the answers before, I could achieve the best result possible (in my opinion) for this.

    showModalBottomSheet(
            context: context,
            backgroundColor: Colors.white,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.only(topLeft: Radius.circular(15.0), topRight: Radius.circular(15.0)),
            ),
            builder: (context) {
              return Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisSize: MainAxisSize.min,
                children: <Widget>[     
                  ListTile(
                    leading: Icon(Icons.email),
                    title: Text('Send email'),
                    onTap: () {
                      print('Send email');
                    },
                  ),
                  ListTile(
                    leading: Icon(Icons.phone),
                    title: Text('Call phone'),
                     onTap: () {
                        print('Call phone');
                      },
                   ),                  
                ],
              );
            });
    
    0 讨论(0)
  • I think the best way to do a rounded-corner modal is to use a RoundedRectangleBorder with a vertical BorderRadius, setting only its top property:

    showModalBottomSheet(
            context: context,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.vertical(top: Radius.circular(25.0)),
            ),
            builder: (BuildContext context) {
              // return your layout
            });
    

    Using separate radii for top left and top right is a bit more verbose and error-prone.

    0 讨论(0)
  • 2020-12-05 02:51

    You can now simply set the shape argument. Example:

    showModalBottomSheet(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.all(Radius.circular(10.0)),
      ),
      context: context,
      builder: (context) => MyBottomSheet(),
    );
    
    0 讨论(0)
提交回复
热议问题