颤振底表和下拉菜单问题

时间:2021-05-17 07:44:10

标签: flutter dart flutter-layout flutter-widget

我正在创建一个 Firebase Flutter 应用程序,其中底部工作表和下拉菜单发生冲突

因为我想要底部工作表上的曲线边框,所以我添加了:

child: MaterialApp(
  debugShowCheckedModeBanner: false,
  theme: ThemeData(
    canvasColor: Colors.transparent,
 ),

然后在我的主页上点击按钮,按下功能被触发:

onPressed: () {
 return showModalBottomSheet(
            context: context,
            builder: (context) {
              return Container(
                      color: Colors.transparent,
                      child: Container(
                      padding:
                        EdgeInsets.symmetric(vertical: 20.0, horizontal: 60.0),
                      decoration: BoxDecoration(
                      color: Colors.purple[200],
                      borderRadius: BorderRadius.only(
                        topLeft: Radius.circular(25.0),
                        topRight: Radius.circular(25.0),
                      )
                    ),
                       child: bottomSheetPanel(),
                    )
                  );
                }
               );

但是当从下拉菜单中选择一个选项时

Emulator shows this

我该如何纠正?

任何帮助将不胜感激:)

1 个答案:

答案 0 :(得分:0)

我正在使用 firebase 发布底部工作表的代码,并且还有下拉菜单,因此您可以从该代码中获取帮助。

Widget updatebottomSheet()
  {

    Size size = MediaQuery.of(context).size;
    String _dropDownValue;
    String starthoour;
    String endhour;
    String startminute;
    String endminute;
    showModalBottomSheet(

        enableDrag: false,
        isDismissible: false,
        isScrollControlled: true,


        context: context,
        builder:(context)
        {
          return GestureDetector(
            behavior: HitTestBehavior.opaque,

            child: SingleChildScrollView(
              child: Container(
                padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom+10),
                // height: size.height*0.6,
                decoration: BoxDecoration(
                  color: Colors.white,

                ),
                child: Column(
                  children: [
                    Padding(
                      padding: const EdgeInsets.all(25.0),
                      child: Container(
                        decoration: BoxDecoration(
                          //color: Colors.red,
                          borderRadius: BorderRadius.circular(20),
                        ),

                        height: size.height*0.6,
                        width: double.infinity,
                        child: Card(
                          elevation: 4,
                          child: Padding(
                            padding: const EdgeInsets.all(12.0),
                            child: Form(
                              key: _formKey,
                              child: Column(
                                mainAxisAlignment: MainAxisAlignment.start,
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [


                                  NameField(

                                    controller: teacherid,
                                    icon: Icons.person,
                                    hintText: "Please enter Teacher id",
                                    text: "you not enter name",

                                    onchanged: (value)
                                    {
                                      Administrative.instance.addteacherId=value;

                                    },


                                  ),
                                  NameField(

                                    controller:name ,
                                    icon: Icons.meeting_room_outlined,
                                    hintText: "Please enter room no",
                                    text: "you not enter room no",

                                    onchanged: (value)
                                    {
                                      Administrative.instance.room=value;

                                    },


                                  ),
                                  FirebaseFirestore.instance.collection("Section").where("collegeId",isEqualTo:cond).snapshots()==null?Container():StreamBuilder(
                                  stream:FirebaseFirestore.instance.collection("Section").where("collegeId",isEqualTo:cond).snapshots(),
                                     builder: (BuildContext context,AsyncSnapshot<QuerySnapshot>snapshot) {



                                         var length = snapshot.data.docs.length;
                                       //  DocumentSnapshot ds = snapshot.data.docs[length];
                                        return DropdownButton(
                                          hint: _dropDownValue==null
                                              ? Text("Choose Section")
                                          :Text(_dropDownValue,style: TextStyle(color: Colors.blue),),
                                          isExpanded: true,
                                          iconSize: 30,
                                        items:snapshot.data.docs.map((DocumentSnapshot document)
                                            {
                                              return  DropdownMenuItem<String>(
                                                value: document.data()["SectionName"],
                                                child: Text(document.data()["SectionName"]),
                                              );
                                            }
                                        ).toList(),
                                          onChanged: (value){
                                             setState(() {
                                               _dropDownValue=value;
                                             });
                                          },

                                        );
                                       }

                                 ),
                              SizedBox(height: 10,),
                              Row(
                                children: [
                                  Padding(
                                    padding: const EdgeInsets.only(right:8.0),
                                    child: Text("Lecture Start time:",style: TextStyle(color: Colors.black,fontWeight: FontWeight.bold),),
                                  ),
                                  Padding(
                                    padding: const EdgeInsets.only(right:20.0),
                                    child: DropdownButton(
                                      hint: starthoour == null
                                          ? Text('Choose')
                                          : Text(
                                        starthoour,
                                        style: TextStyle(color: Colors.blue),
                                      ),
                                      isExpanded: false,
                                      iconSize: 40.0,
                                      style: TextStyle(color: Colors.blue),
                                      items: ['7 AM', '8 AM', '9 AM',"10 AM","11 AM","12 AM","1 PM","2 PM","3 PM","4 PM","5 PM","6 PM","7 PM","8 PM","9 PM","10 PM"].map(
                                            (val) {
                                          return DropdownMenuItem<String>(
                                            value: val,
                                            child: Text(val),
                                          );
                                        },
                                      ).toList(),
                                      onChanged: (val) {
                                        setState(
                                              () {
                                            starthoour = val;
                                          },
                                        );
                                      },
                                    ),
                                  ),
                                  DropdownButton(
                                    hint: startminute == null
                                        ? Text('Choose')
                                        : Text(
                                      startminute,
                                      style: TextStyle(color: Colors.blue),
                                    ),
                                    isExpanded: false,
                                    iconSize: 40.0,
                                    style: TextStyle(color: Colors.blue),
                                    items: ['10', '20', '30',"40","50","60"].map(
                                          (val) {
                                        return DropdownMenuItem<String>(
                                          value: val,
                                          child: Text(val),
                                        );
                                      },
                                    ).toList(),
                                    onChanged: (val) {
                                      setState(
                                            () {
                                          startminute = val;
                                        },
                                      );
                                    },
                                  ),
                                ],
                              ),
                                  SizedBox(height: 20,),
                                  Row(
                                    children: [
                                      Padding(
                                        padding: const EdgeInsets.only(right:8.0),
                                        child: Text("Lecture End time:",style: TextStyle(color: Colors.black,fontWeight: FontWeight.bold),),
                                      ),
                                      Padding(
                                        padding: const EdgeInsets.only(right:20.0),
                                        child: DropdownButton(
                                          hint: endhour == null
                                              ? Text('Choose')
                                              : Text(
                                            endhour,
                                            style: TextStyle(color: Colors.blue),
                                          ),
                                          isExpanded: false,
                                          iconSize: 40.0,
                                          style: TextStyle(color: Colors.blue),
                                          items: ['7 AM', '8 AM', '9 AM',"10 AM","11 AM","12 AM","1 PM","2 PM","3 PM","4 PM","5 PM","6 PM","7 PM","8 PM","9 PM","10 PM"].map(
                                                (val) {
                                              return DropdownMenuItem<String>(
                                                value: val,
                                                child: Text(val),
                                              );
                                            },
                                          ).toList(),
                                          onChanged: (val) {
                                            setState(
                                                  () {
                                                endhour = val;
                                              },
                                            );
                                          },
                                        ),
                                      ),
                                      DropdownButton(
                                        hint: endminute == null
                                            ? Text('Choose')
                                            : Text(
                                          endminute,
                                          style: TextStyle(color: Colors.blue),
                                        ),
                                        isExpanded: false,
                                        iconSize: 40.0,
                                        style: TextStyle(color: Colors.blue),
                                        items: ['10', '20', '30',"40","50","60"].map(
                                              (val) {
                                            return DropdownMenuItem<String>(
                                              value: val,
                                              child: Text(val),
                                            );
                                          },
                                        ).toList(),
                                        onChanged: (val) {
                                          setState(
                                                () {
                                              endminute = val;
                                            },
                                          );
                                        },
                                      ),
                                    ],
                                  ),



                                ],
                              ),
                            ),
                          ),

                        ),
                      ),
                    ),
                    Padding(
                      padding: const EdgeInsets.only(left: 20.0,right: 20.0,top: 8.0,bottom: 8.0),
                      child: Container(
                        width: double.infinity,
                        height: 60,
                        child: FlatButton(
                          color: Colors.black,
                          onPressed: () {
                            if(!_formKey.currentState.validate()){
                              return;
                            }
                           else
                             {
                               if(_dropDownValue==null||endminute==null||endhour==null||startminute==null||starthoour==null)
                                 {
                                   Fluttertoast.showToast(
                                       msg: "Please choose properly from DropDown",
                                       toastLength: Toast.LENGTH_LONG,
                                       gravity: ToastGravity.CENTER,
                                       timeInSecForIosWeb: 1,
                                       backgroundColor: Colors.redAccent,
                                       textColor: Colors.white,
                                       fontSize: 16.0

                                   );
                                 }
                               else
                                 {
                                   _formKey.currentState.validate();
                                   addslot(_dropDownValue,starthoour,startminute,endhour,endminute);
                                 }

                             }

                          },
                          shape: RoundedRectangleBorder(
                            borderRadius: BorderRadius.circular(10.0),

                          ),
                          child: Text("Save",style: TextStyle(color: Colors.white,fontSize: 18,fontWeight: FontWeight.bold),),
                        ),
                      ),
                    ),
                    Padding(
                      padding: const EdgeInsets.only(left: 20.0,right: 20.0,top: 8.0,bottom: 8.0),
                      child: Container(
                        width: double.infinity,
                        height: 60,
                        child: FlatButton(
                          color: Colors.black,
                          onPressed: (){
                            Navigator.pop(context);
                          },
                          shape: RoundedRectangleBorder(
                            borderRadius: BorderRadius.circular(10.0),

                          ),
                          child: Text("Cancel",style: TextStyle(color: Colors.white,fontSize: 18,fontWeight: FontWeight.bold),),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ),
          );
        }


    );

  }