繁体   English   中英

如何检测 Flutter 中 Drawer 的数据变化?

[英]How to detect data changes from Drawer in Flutter?

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

这是homePage.dart's Scaffold。 抽屉进口如下:

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),
                      );
                    }));
          },
        ),
      )]
));
}

如您所见,我正在尝试更改子文本颜色。 我在 Provider 中执行此操作,但是如果不热重新加载,我看不到颜色变化。 当我添加notifyListeners(); , 抽屉关闭。

gif给你看..

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM