【问题标题】:The method 'showSnackBar' isn't defined for the type 'BuildContext'没有为“BuildContext”类型定义方法“showSnackBar”
【发布时间】:2021-09-01 19:03:12
【问题描述】:

在这里我创建了一个 DropdownItemMenu,它从 firebase 集合中获取元素,但它显示了一个错误

没有为类型“BuildContext”定义方法“showSnackBar”

Container(
                    margin: EdgeInsets.only(left: 16, right: 16),
                    height: MediaQuery.of(context).size.height * 0.10,
                    child: Card(
                      child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: DropdownButton<String>(
                          isExpanded: false,
                          style: TextStyle(
                              fontSize: 14, color: Colors.blueGrey),
                          icon: const Icon(Icons.keyboard_arrow_down),
                          underline: Container(color: Colors.transparent),
                          onChanged: (serieValue) {
                            final snackBar = SnackBar(
                                content: Text(
                              'Série selectionnée est $serieValue',
                              style: TextStyle(
                                  fontWeight: FontWeight.bold,
                                  fontSize: 14,
                                  color: Color(0xff11b719)),
                            ));
                            Scaffold.of(context.showSnackBar(snackBar));


                            setState(() {
                              selectedIndexSerie = serieValue;
                            });
                          },
                          value: selectedIndexSerie,
                          hint: Text(
                            'Selectionner une série',
                            style: TextStyle(
                                fontWeight: FontWeight.bold,
                                fontSize: 14,
                                color: Color(0xff11b719)),
                          ),
                          items: series,
                        ),
                      ),
                    ),
                  );

【问题讨论】:

    标签: firebase flutter snackbar flutter-dropdownbutton


    【解决方案1】:

    你放错了')' -->

    Scaffold.of(context).showSnackBar(snackBar);
    

    另外,showSnackBar 已弃用,请考虑使用 ScaffoldMessenger

    ScaffoldMessenger.of(context).showSnackBar(snackBar);
    

    【讨论】:

      猜你喜欢
      • 2021-09-17
      • 2021-07-26
      • 2021-04-15
      • 1970-01-01
      • 2021-06-19
      • 2021-02-11
      • 2021-09-02
      • 2022-11-21
      • 2021-10-19
      相关资源
      最近更新 更多