Android 如何在颤振中检测抽屉中的数据变化?
我有一个抽屉用于过滤我的产品,我的抽屉是从另一个dart文件导入的,就像这样 这是Android 如何在颤振中检测抽屉中的数据变化?,android,flutter,dart,navigation-drawer,drawer,Android,Flutter,Dart,Navigation Drawer,Drawer,我有一个抽屉用于过滤我的产品,我的抽屉是从另一个dart文件导入的,就像这样 这是主页。dart的脚手架。抽屉导入方式如下: return Scaffold( key: _scaffoldkey, appBar:AppBar( leading: IconButton( icon: Icon(Icons.arrow_back, color: Colors.black), onPressed: () => Na
主页。dart的脚手架。抽屉导入方式如下:
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),
);
}));
},
),
)]
));
}
容器过滤器绘图器(上下文){
TextStyle childStyle=TextStyle(字体大小:14);
TextStyle childActiveStyle=TextStyle(fontSize:14,颜色:primaryColor);
var\u superpo=Provider.of(上下文,侦听:false);
返回容器(
颜色:颜色,白色,
宽度:MediaQuery.of(context).size.width*0.75,
子:列(
儿童:[扩大(
子项:ListView.builder(
itemCount:_superpo.storeFilterList.length,
itemBuilder:(上下文,索引){
return _superpo.storeFilterList[索引]['options']。长度==0
?尺寸箱(
高度:0.1,
)
:扩展文件(
标题:文本(_superpo.storeFilterList[index]['name']),
儿童填充:仅限边缘组(左:10),
子项:List.generate(
_superpo.storeFilterList[index]['options'].length,
(子索引){
返回列表块(
onTap:(){
_superpo.setFilterData(
_Superpo.storeFilterList[索引]
['filterQueryName']
.toString(),
_superpo.storeFilterList[索引]['options']
[子索引]['id']);
},
尾随:图标(图标。检查圆圈和轮廓),
标题:文本(_superpo.storeFilterList[index][options'][subIndex][name'],
样式:_superpo.filterQueryList[_superpo.storeFilterList[索引]['filterQueryName'].toString()!=null
(\u superpo.过滤器查询列表[\u superpo
.storeFilterList[索引]
['filterQueryName']
.toString()]
.containsKey(_superpo
.storeFilterList[索引]
['options'][子索引]
['id']
.toString())==
真的
?儿童风格
:儿童风格)
:儿童风格),
);
}));
},
),
)]
));
}
如您所见,我正在尝试更改子文本的颜色。我在提供程序中执行此操作,但是如果没有热重新加载,我看不到颜色的变化。当我添加notifyListeners()时代码>,抽屉关闭
Gif给你看
我的问题解决了我通过删除脚手架钥匙解决了错误,但我不知道如何在没有脚手架钥匙的情况下以编程方式打开抽屉。您使用无状态小部件吗?不,我不使用。我使用StateFulWidget作为主页,但我的抽屉只是一个容器方法。