0

我有一个像这样的提供者:

final profileImagesProvider =
    ChangeNotifierProvider.family<ProfileImagesNotifier, List<String>>(
        (ref, profileImages) => ProfileImagesNotifier(profileImages));

class ProfileImagesNotifier extends ChangeNotifier {
  ProfileImagesNotifier(List<String> images);

  List<String> images;
}

但是,当我尝试使用提供程序时:

Widget build(BuildContext context, ScopedReader watch) {
  var profileImages = watch(ProfileImagesNotifier(['test_1.png', 'test_2.png']))
  print(profileImages.images) //null
}

该列表作为空值检索。

我这样做对吗?(在河流 pod 和状态管理方面,我完全是个菜鸟)。

4

1 回答 1

0

错误地调用了构造函数。

本来应该:

ProfileImagesNotifier(this.images);

而不是

ProfileImagesNotifier(List<String> images);
于 2020-12-14T14:50:06.753 回答