如何从Flutter中的Drawer中检测数据更改?

问题描述

我有一个用于过滤产品的抽屉,我的抽屉是从另一个这样的飞镖文件导入的。

这是homePage.dart's支架。导入的抽屉如下:

return Scaffold(
  key: _scaffoldkey,appBar:AppBar(
          leading: IconButton(
              icon: Icon(Icons.arrow_back,color: Colors.black),onpressed: () => Navigator.pop(context)),backgroundColor: Colors.white,title: Text('HomePage',style: TextStyle(color: Colors.black),textAlign: TextAlign.left),),endDrawer:filterDrawer(context),

这是filterDrawer.dart文件

Container filterDrawer(context) {
 TextStyle childStyle = TextStyle(fontSize: 14);
  TextStyle childActiveStyle = TextStyle(fontSize: 14,color: primaryColor);
  var _supRepo = Provider.of<supplierRepo>(context,listen: false);
  return Container(
      color: Colors.white,width: MediaQuery.of(context).size.width * 0.75,child: Column(
        children: [Expanded(
        child: ListView.builder(
          itemCount: _supRepo.storeFilterList.length,itemBuilder: (context,index) {
            return _supRepo.storeFilterList[index]['options'].length == 0
                ? SizedBox(
                    height: 0.1,)
                : ExpansionTile(
                    title: Text(_supRepo.storeFilterList[index]['name']),childrenPadding: EdgeInsets.only(left: 10),children: List<Widget>.generate(
                        _supRepo.storeFilterList[index]['options'].length,(subIndex) {
                      return ListTile(
                        onTap:() {
                          _supRepo.setFilterData(
                              _supRepo.storeFilterList[index]
                                      ['filterQueryName']
                                  .toString(),_supRepo.storeFilterList[index]['options']
                                  [subIndex]['id']);
                        },trailing: Icon(Icons.check_circle_outline),title: Text(_supRepo.storeFilterList[index]['options'][subIndex]['name'],style: _supRepo.filterQueryList[_supRepo.storeFilterList[index]['filterQueryName'].toString()] != null
                                ? (_supRepo.filterQueryList[_supRepo
                                                .storeFilterList[index]
                                                    ['filterQueryName']
                                                .toString()]
                                            .containsKey(_supRepo
                                                .storeFilterList[index]
                                                    ['options'][subIndex]
                                                    ['id']
                                                .toString()) ==
                                        true
                                    ? childActiveStyle
                                    : childStyle)
                                : childStyle),);
                    }));
          },)]
));
}

如您所见,我正在尝试更改子文本的颜色。我在提供程序中执行此操作,但是如果不进行热重装,则看不到颜色变化。当我添加notifyListeners();时,抽屉关闭

Gif,你看..

https://gifyu.com/image/4DFn

解决方法

我的问题已解决,我通过删除scaffoldKey解决了该错误,但是我不知道如何在没有scaffoldKey的情况下以编程方式打开抽屉。.

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...