【问题标题】:how to get custom bottom sheet like one in image? curved bottom sheet in flutter如何获得像图像中的自定义底页?颤动的弯曲底板
【发布时间】:2020-08-26 07:09:29
【问题描述】:

我尝试在我的颤振应用中制作一些自定义底页。我试图在container 中使用圆形矩形边框在我的工作表中添加灰色背景。但为什么它不起作用? 这是我的代码和输出:

 void _modalBottomSheetMenu4(){
    showModalBottomSheet(
        context: context,
        builder: (builder){
          return new Container(
            height: 350.0,
            color: Colors.grey[350],
            child: new Container(
                decoration: new BoxDecoration(
                    color: Colors.white,
                    borderRadius: new BorderRadius.only(
                        topLeft: const Radius.circular(3.0),
                        topRight: const Radius.circular(3.0))),
                        //content starts
                child: new Container(
                  margin: EdgeInsets.only(right: 5.0,left: 5.0,top: 10.0),                 
            child: new Column(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[

// rounded rectangle grey handle
                new Container(
                  width: 40.0,
                  height: 5.0,                 
        decoration:
                new BoxDecoration(
                  borderRadius: new BorderRadius.circular(10.0),
                  color: Colors.grey,
                ),
),

               
new Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
        
                 new SvgPicture.asset("assets/lang.svg", width: 80.0, height: 80.0, ),
                  
          new Text("\nSelect Language\n",
          style: TextStyle(color: Colors.black,fontWeight: FontWeight.bold, fontSize:20.0 )),

           new Container(
             padding: EdgeInsets.all(5.0),
            child: new CupertinoButton(   //special button for ios on click fadecolor
              onPressed: () async{
                        Navigator.pop(context);
                       Navigator.of(context).push(new MaterialPageRoute(builder: (BuildContext context) => new GreetingPage())); 
                              },
                              child: new Text(" Tamil "),
                              color: CupertinoColors.activeBlue,
                              pressedOpacity: 0.4 ,          //opactiy default 0.1
                              minSize: 44.0,                //its has min length 
                
                            ),
                          ),


                           new Container(
                             padding: EdgeInsets.all(5.0),
            child: new CupertinoButton(   //special button for ios on click fadecolor
              onPressed: () async{
                      Navigator.pop(context);
                     Navigator.of(context).push(new MaterialPageRoute(builder: (BuildContext context) => new GreetingPageEng())); 
                              },
                              child: new Text("English"),
                              color: CupertinoColors.destructiveRed,
                              pressedOpacity: 0.4 ,          //opactiy default 0.1
                              minSize: 44.0,                //its has min length 
                
                            ),
                          ),


                              ],
                            ),
                             SizedBox(height: 30.0),
              ],
            ),
                                ),
                            ),
                          );
                        }
                    );
                  }
    

我的输出:

预期输出:

在我的底页中看不到弯曲的边缘。

我在代码中犯了什么错误?
我怎样才能做到这一点?

提前致谢。

【问题讨论】:

    标签: flutter dart flutter-layout bottom-sheet flutter-animation


    【解决方案1】:

    您可以使用BottomSheetshape 属性为BottomSheet 赋予圆角。

    您将shape 属性设置为RoundedRectangleBorder 并为其指定borderRadius 属性。

    检查下面的代码:它运行良好:

    void _modalBottomSheetMenu4(){
      showModalBottomSheet(
          context: context,
          // use the shape border property to give it rounder corners
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.only(
              topLeft: Radius.circular(20),
              topRight: Radius.circular(20),
            ),
          ),
          builder: (builder){
            return new Container(
              height: 350.0,
              color: Colors.grey[350],
              child: new Container(
                decoration: new BoxDecoration(
                    color: Colors.white,
                    borderRadius: new BorderRadius.only(
                        topLeft: const Radius.circular(3.0),
                        topRight: const Radius.circular(3.0))),
                //content starts
                child: new Container(
                  margin: EdgeInsets.only(right: 5.0,left: 5.0,top: 10.0),
                  child: new Column(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
    
    // rounded rectangle grey handle
                      new Container(
                        width: 40.0,
                        height: 5.0,
                        decoration:
                        new BoxDecoration(
                          borderRadius: new BorderRadius.circular(10.0),
                          color: Colors.grey,
                        ),
                      ),
    
    
                      new Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: <Widget>[
    
                          new SvgPicture.asset("assets/lang.svg", width: 80.0, height: 80.0, ),
    
                          new Text("\nSelect Language\n",
                              style: TextStyle(color: Colors.black,fontWeight: FontWeight.bold, fontSize:20.0 )),
    
                          new Container(
                            padding: EdgeInsets.all(5.0),
                            child: new CupertinoButton(   //special button for ios on click fadecolor
                              onPressed: () async{
                                Navigator.pop(context);
                                Navigator.of(context).push(new MaterialPageRoute(builder: (BuildContext context) => new GreetingPage()));
                              },
                              child: new Text(" Tamil "),
                              color: CupertinoColors.activeBlue,
                              pressedOpacity: 0.4 ,          //opactiy default 0.1
                              minSize: 44.0,                //its has min length 
    
                            ),
                          ),
    
    
                          new Container(
                            padding: EdgeInsets.all(5.0),
                            child: new CupertinoButton(   //special button for ios on click fadecolor
                              onPressed: () async{
                                Navigator.pop(context);
                                Navigator.of(context).push(new MaterialPageRoute(builder: (BuildContext context) => new GreetingPageEng()));
                              },
                              child: new Text("English"),
                              color: CupertinoColors.destructiveRed,
                              pressedOpacity: 0.4 ,          //opactiy default 0.1
                              minSize: 44.0,                //its has min length 
    
                            ),
                          ),
    
    
                        ],
                      ),
                      SizedBox(height: 30.0),
                    ],
                  ),
                ),
              ),
            );
          }
      );
    }
    

    我希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-09
      • 2021-11-29
      • 1970-01-01
      • 2022-01-16
      • 2020-03-09
      • 1970-01-01
      • 2022-10-07
      • 1970-01-01
      相关资源
      最近更新 更多