Flutter 通知侦听器不更新UI
通知程序类Flutter 通知侦听器不更新UI,flutter,notify,Flutter,Notify,通知程序类 class CategoryProvider with ChangeNotifier { DocumentSnapshot? doc; String? selectedCategory; List<String> urlList = []; setCategory(selectedCat) { this.selectedCategory = selectedCat; notifyListeners(); } setCatSna
class CategoryProvider with ChangeNotifier {
DocumentSnapshot? doc;
String? selectedCategory;
List<String> urlList = [];
setCategory(selectedCat) {
this.selectedCategory = selectedCat;
notifyListeners();
}
setCatSnapshot(DocumentSnapshot snapshot) {
this.doc = snapshot;
notifyListeners();
}
addImages(url) {
this.urlList.add(url);
notifyListeners();
}
}
class CategoryProvider和ChangeNotifier{
文档快照?文档;
字符串?选择的类别;
列表URL列表=[];
设置类别(已选择的类别){
this.selectedCategory=selectedCat;
notifyListeners();
}
setCatSnapshot(文档快照快照){
this.doc=快照;
notifyListeners();
}
添加图像(url){
this.urlist.add(url);
notifyListeners();
}
}
需要使用新URL列表更新的小部件
但是,打印长度会给出更新的url列表值
我确实尝试过直接传递_provider.urlist,但问题是相同的
Widget loadGalary(BuildContext context) {
print(_provider.urlList.length.toString());
List<String> urlList = List.from(_provider.urlList);
return GalleryImage(
titileGallery: 'Galary',
imageUrls: urlList,
);
}
Widget-loadGalary(构建上下文){
打印(_provider.urlist.length.toString());
List urlist=List.from(_provider.urlist);
返回GalleryImage(
titileGallery:“Galary”,
imageUrls:urlList,
);
}
WrapGalleryImage
在消费者
或选择器
中。尝试过,但仍有问题