Flutter Provider 不会重建小部件

Fra*_*cca 6 dart flutter flutter-provider

这是我的一段代码,但请在得出结论之前先阅读问题:

class RescheduleCard extends StatelessWidget {

@override
  Widget build(BuildContext context)=> Consumer<AppSnapshot>(
    builder: (context, appSnapshot, _)=>
    (appSnapshot.reschedule!=null)
    ?RescheduleBuilder(
          model: appSnapshot.reschedule,
          controllers: appSnapshot.controllers,
        )
    :Carouselcard(
      title:  carouselPageTitle(title: rescheduleTitle,test: appSnapshot.test),
      colors: yellows,
Run Code Online (Sandbox Code Playgroud)

所以我对提供者有点陌生,我习惯了 Bloc,我的 api 一旦收到一些调用提供者并设置模型;

编辑:这里是提供商 256 条线路,涉及“重新安排”的问题......

class AppSnapshot with ChangeNotifier {

  RescheduleModel _reschedule;
  RescheduleModel get reschedule => _reschedule;

  void cleanReschedule() {
    reschedule=null;
    notifyListeners();
  }

  set reschedule(RescheduleModel reschedule) {
    _reschedule=reschedule;
    notifyListeners();
  }
}
Run Code Online (Sandbox Code Playgroud)

重新编辑:最重要的是:

void main() async {
  final AppSnapshot _appSnapshot = AppSnapshot();
  await _appSnapshot.load();
  runApp(ChangeNotifierProvider(
          builder: (context) => _appSnapshot,
          child: Initializer()));
}
Run Code Online (Sandbox Code Playgroud)

我期待“消费者”重建我的小部件,但没有!

我确信数据在那里,因为该小部件位于轮播内部,一旦我移动它,它就会正确重建。

我缺少什么?谢谢

重新重新编辑:这是另一个轮播卡的示例,其中提供商快速工作并且实时应用更改

 Consumer<AppSnapshot>(
    builder: (context, appSnapshot, _)=> Carouselcard(
      title: carouselPageTitle(title: optionsTitle,test: appSnapshot.test),
      colors: lightBlues,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          ((appSnapshot.id??'')!='')                                                        // ID WIDGET
            ? ListTile(
              leading: CustomIcon(
                icon: deleteIcon,
                onTap: () => appSnapshot.deleteID(),
              ),
              title: _customCard(onTap:()=> _showID(id: appSnapshot.id,context: context)),
              subtitle: Text(tap2delete,textScaleFactor:0.8),
            )
            : IdTile(), 
Run Code Online (Sandbox Code Playgroud)

Bri*_*den 2

根据这篇文章,它FutureProvider不会监听更改,它只会Consumers在 Future 完成时重建 1 次。

文章甚至解释了作者如何测试这一点。

Dart Provider 包的开发人员还解释FutureProvider.