How do you adjust the height and borderRadius of a BottomSheet in Flutter?

后端 未结 9 1243
野性不改
野性不改 2021-02-05 03:47

I\'m probably missing something obvious here, but my BottomSheet only takes up the bottom half the screen, even though the widgets in it take up more space. So now there is scro

相关标签:
9条回答
  • 2021-02-05 04:18

    It's possible this way

    showModalBottomSheet(
      context: context,
      isScrollControlled: true,
      backgroundColor: Colors.transparent,
      builder: (context) => Container(
        height: MediaQuery.of(context).size.height * 0.75,
        decoration: new BoxDecoration(
          color: Colors.white,
          borderRadius: new BorderRadius.only(
            topLeft: const Radius.circular(25.0),
            topRight: const Radius.circular(25.0),
          ),
        ),
        child: Center(
          child: Text("Modal content goes here"),
        ),
      ),
    );
    
    1. Set isScrollControlled: true and backgroundColor: Colors.transparent for the modal
    2. Provide a Container with required height: as root widget to modal builder
    3. Provide BoxDecoration with required borderRadius for the Container

    0 讨论(0)
  • 2021-02-05 04:18

    Use the Code Below

    Note : If You are using column then use mainAxisSize: MainAxisSize.min

    
    // make isScrollControlled : true
    // if using column then make - mainAxisSize: MainAxisSize.min
    
    showModalBottomSheet<dynamic>(
    isScrollControlled: true,
    context: context,
    builder: (BuildContext bc) {
      return YourWidget();
     }
    )
    
    0 讨论(0)
  • 2021-02-05 04:27

    Lately I found an workaround for this. By setting the canvasColor property to Colors.transparent in your app's theme, we can make the BottomSheet's overlay disappear.

    return new MaterialApp(
      title: 'MyApp',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
        canvasColor: Colors.transparent,
      ),
      //...
    );
    

    Once you set this up, you may use ClipRRect or Decoration with rounded corners.

    0 讨论(0)
提交回复
热议问题