Flutter 如何在颤振中实现弹出菜单内的下拉

Flutter 如何在颤振中实现弹出菜单内的下拉,flutter,flutter-layout,Flutter,Flutter Layout,我需要一个弹出菜单或任何其他方式来实现在颤振。我曾尝试在弹出视图中实现它,但没有成功。请帮我解决这个问题 这是我尝试过的代码,使用任何其他方法实现它也可以。此代码给出错误未找到任何材料小部件,如果可以修复,也将对我有所帮助 void showFilter() { showGeneralDialog( barrierLabel: "Barrier", barrierDismissible: true, barrierColor: Co

我需要一个弹出菜单或任何其他方式来实现在颤振。我曾尝试在弹出视图中实现它,但没有成功。请帮我解决这个问题

这是我尝试过的代码,使用任何其他方法实现它也可以。此代码给出错误未找到任何材料小部件,如果可以修复,也将对我有所帮助

void showFilter() {
    showGeneralDialog(
      barrierLabel: "Barrier",
      barrierDismissible: true,
      barrierColor: Colors.black.withOpacity(0.5),
      transitionDuration: Duration(milliseconds: 700),
      context: context,
      pageBuilder: (_, __, ___) {
        return Align(
          alignment: Alignment.center,
          child: Container(
            height: 300,
            child: SizedBox.expand(
                child:Column(
                  children: <Widget>[
                    Container(
                      padding: EdgeInsets.only( top: SizeConfig.blockSizeHorizontal*2, left: SizeConfig.blockSizeHorizontal*6),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.start,
                        children: <Widget>[
                          Text("Monthly Summary", style: TextStyle(fontSize: SizeConfig.blockSizeHorizontal*6, color: Colors.black87,decoration: TextDecoration.none,),),
                        ],
                      )
                    ),
                    Container(
                      padding: EdgeInsets.only(top:SizeConfig.blockSizeHorizontal*2, left: SizeConfig.blockSizeHorizontal*3, right: SizeConfig.blockSizeHorizontal*3),
                      child: Divider(
                        color: Colors.black87,thickness: 2.0,
                      ),
                    ),
                        Container(
                            padding: EdgeInsets.only(left: SizeConfig.blockSizeHorizontal*6, top: SizeConfig.blockSizeHorizontal*4),
                            child: Row(
                              children: <Widget>[
                                Container(
                                  child: Row(
                                    children: <Widget>[
                                      Text("Year - ", style: TextStyle(fontSize: SizeConfig.blockSizeHorizontal*4.5, color: Colors.black87,decoration: TextDecoration.none,),)
                                    ],
                                  ),
                                ),
                                Container(
                                  child: Row(
                                    children: <Widget>[
                                      Container(
                                        child: DropdownButton(
                                          value: _dpdValue,
                                          underline: Container(),
                                          isExpanded: true,
                                          iconSize: 30.0,
                                          items: _dropdownValues.map((val) {
                                            return new DropdownMenuItem<String>(
                                              value: val,
                                              child: new Text(val),
                                            );
                                          }).toList(),
                                          onChanged: (val) {
                                            if (!mounted) return;
                                            setState(
                                                  () {
                                                _dpdValue = val;
                                              },
                                            );
                                          },
                                        ),
                                      )
                                    ],
                                  ),
                                )
                              ],
                            )
                        )
                      ],
                )
            ),
            margin: EdgeInsets.only(top: SizeConfig.blockSizeHorizontal*15, left: SizeConfig.blockSizeHorizontal*3, right: SizeConfig.blockSizeHorizontal*3),
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.circular(SizeConfig.blockSizeHorizontal*6),
            ),
          ),
        );
      },
      transitionBuilder: (_, anim, __, child) {
        return SlideTransition(
          position: Tween(begin: Offset(0, 1), end: Offset(0, 0)).animate(anim),
          child: child,
        );
      },
    );
  }
void showFilter(){
显示通用对话框(
障碍物标签:“障碍物”,
是的,
背景色:颜色。黑色。不透明度(0.5),
转换持续时间:持续时间(毫秒:700),
上下文:上下文,
页面生成器:(\uuuuuuuuuuuuuuuuuuuuuuuuuu){
返回对齐(
对齐:对齐.center,
子:容器(
身高:300,
子项:SizedBox.expand(
子:列(
儿童:[
容器(
填充:仅限边集(顶部:SizeConfig.blockSizeHorizontal*2,左侧:SizeConfig.blockSizeHorizontal*6),
孩子:排(
mainAxisAlignment:mainAxisAlignment.start,
儿童:[
文本(“每月摘要”,样式:TextStyle(fontSize:SizeConfig.blockSizeHorizontal*6,颜色:Colors.black87,装饰:TextDecoration.none,),),
],
)
),
容器(
填充:仅限边集(顶部:SizeConfig.blockSizeHorizontal*2,左侧:SizeConfig.blockSizeHorizontal*3,右侧:SizeConfig.blockSizeHorizontal*3),
孩子:分割器(
颜色:颜色。黑色87,厚度:2.0,
),
),
容器(
填充:仅限边集(左:SizeConfig.blockSizeHorizontal*6,上:SizeConfig.blockSizeHorizontal*4),
孩子:排(
儿童:[
容器(
孩子:排(
儿童:[
文本(“年份-”,样式:TextStyle(fontSize:SizeConfig.blockSizeHorizontal*4.5,颜色:Colors.black87,装饰:textEdition.none,),)
],
),
),
容器(
孩子:排(
儿童:[
容器(
孩子:下拉按钮(
值:dpdValue,
下划线:Container(),
是的,
iconSize:30.0,
项目:_dropdownValues.map((val){
返回新的DropdownMenuItem(
值:val,
子项:新文本(val),
);
}).toList(),
一旦更改:(val){
如果(!已安装)返回;
设定状态(
() {
_dpdValue=val;
},
);
},
),
)
],
),
)
],
)
)
],
)
),
页边空白:仅限边集(顶部:尺寸图块尺寸水平*15,左侧:尺寸图块尺寸水平*3,右侧:尺寸图块尺寸水平*3),
装饰:盒子装饰(
颜色:颜色,白色,
borderRadius:borderRadius.圆形(SizeFig.BlockSize水平*6),
),
),
);
},
transitionBuilder:(_,动画,_,子){
返回幻灯片转换(
位置:吐温(开始:偏移(0,1),结束:偏移(0,0))。动画(动画),
孩子:孩子,
);
},
);
}

我已经为此使用了Alertdialog,,希望它能为解决您的问题提供见解

 int year = 1990;
 List<String> months = ['January', 'February', 'March'];
  List<String> years = [];
  String option, month;

  @override
  void initState() {
    super.initState();
    for (int i = year; i < 2020; i++) {
      years.add(i.toString());
    }
  }

  Future<bool> errorDialog(context) async {
    Size size = MediaQuery.of(context).size;
    return showDialog(
        context: context,
        barrierDismissible: false,
        builder: (BuildContext context) {
          return StatefulBuilder(builder: (context, setState) {
            return AlertDialog(
              backgroundColor: Colors.white,
              shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.all(Radius.circular(20.0))),
              content: Padding(
                padding: const EdgeInsets.all(8.0),
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: <Widget>[
                     Padding(
                       padding: const EdgeInsets.all(8.0),
                       child: Text("Monthly Summary"),
                     ),
                    Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: <Widget>[
                          Text('Year-'),
                          Container(
                            width: size.width * 0.5,
                            decoration: BoxDecoration(
                                border: Border.all(
                                    color:Colors.amber),
                                borderRadius:
                                    BorderRadius.all(Radius.circular(5))),
                            child: DropdownButtonFormField<String>(
                              decoration: InputDecoration(
                                  contentPadding:
                                      EdgeInsets.fromLTRB(10, 0, 10, 0),
                                  filled: true,
                                  fillColor: Colors.white,
                                  hintText: 'Select Year',
                                  hintStyle:
                                      TextStyle(fontWeight: FontWeight.normal)),
                              value: option,
                              icon: Icon(Icons.arrow_drop_down),
                              iconSize: 24,
                              elevation: 16,
                              style: TextStyle(color: Colors.black),
                              onChanged: (String newValue) {
                                setState(() {
                                  option = newValue;
                                });
                              },
                              validator: (value) {
                                if (value == null) {
                                  return "Select Year";
                                }
                                return null;
                              },
                              items: years
                                  .map<DropdownMenuItem<String>>((String option) {
                                return DropdownMenuItem<String>(
                                  value: option,
                                  child: Text(option),
                                );
                              }).toList(),
                            ),
                          ),
                        ],
                      ),
                    ),
                    Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: <Widget>[
                          Text('Month-'),
                          Container(
                            decoration: BoxDecoration(
                                border: Border.all(
                                    color:Colors.amber),
                                borderRadius:
                                    BorderRadius.all(Radius.circular(5))),
                            width: size.width * 0.5,
                            child: DropdownButtonFormField<String>(
                              decoration: InputDecoration(
                                  contentPadding:
                                      EdgeInsets.fromLTRB(10, 0, 10, 0),
                                  filled: true,
                                  fillColor: Colors.white,
                                  hintText: 'Select Month',
                                  hintStyle:
                                      TextStyle(fontWeight: FontWeight.normal)),
                              value: month,
                              icon: Icon(Icons.arrow_drop_down),
                              iconSize: 24,
                              elevation: 16,
                              style: TextStyle(color: Colors.black),
                              onChanged: (String newValue) {
                                setState(() {
                                  month = newValue;
                                });
                              },
                              validator: (value) {
                                if (value == null) {
                                  return "Select Month";
                                }
                                return null;
                              },
                              items: months
                                  .map<DropdownMenuItem<String>>((String option) {
                                return DropdownMenuItem<String>(
                                  value: option,
                                  child: Text(option),
                                );
                              }).toList(),
                            ),
                          ),
                        ],
                      ),
                    ),
                    Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                        children: <Widget>[
                          Padding(
                            padding: const EdgeInsets.all(8.0),
                            child: RaisedButton(
                              color: Colors.amber,
                              shape: RoundedRectangleBorder(
                                  borderRadius:
                                      BorderRadius.all(Radius.circular(2.0))),
                              child: Text(
                                "CANCEL",
                                style: TextStyle(color: Colors.black),
                              ),
                              onPressed: () {
                                Navigator.of(context).pop();
                              },
                            ),
                          ),
                          Padding(
                            padding: const EdgeInsets.all(8.0),
                            child: RaisedButton(
                              color: Colors.amber,
                              shape: RoundedRectangleBorder(
                                  borderRadius:
                                      BorderRadius.all(Radius.circular(2.0))),
                              child: Text(
                                "SEARCH",
                                style: TextStyle(color: Colors.black),
                              ),
                              onPressed: () {
                                Navigator.of(context).pop();
                              },
                            ),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            );
          });
        });
  }
int年=1990年;
列出月份=[‘一月’、‘二月’、‘三月’];
列表年份=[];
字符串选项,月;
@凌驾
void initState(){
super.initState();
对于(int i=年份;i<2020;i++){
年。添加(i.toString());
}
}
未来错误对话框(上下文)异步{
Size Size=MediaQuery.of(context).Size;
返回显示对话框(
上下文:上下文,
禁止:错误,
生成器:(BuildContext上下文){
返回StatefulBuilder(生成器:(上下文,设置状态){
返回警报对话框(
背景颜色:Colors.white,
形状:圆形矩形边框(
borderRadius:borderRadius.all(半径.圆形(20.0)),
内容:填充(
填充:常数边集全部(8.0),
子:列(
mainAxisSize:mainAxisSize.min,
儿童:[
填充物(
填充:常数边集全部(8.0),
子项:文本(“每月摘要”),
),
填充物(
填充:常数边集全部(8.0),