6

here's a piece of my code, but please read the question before jumping to conclusions:

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,

so I'm sort of new to provider and I'm used to Bloc, my api once receive some call the provider and set a model;

edit: here's the provider 256 lines tripped down to what concern the "reschedule"...

class AppSnapshot with ChangeNotifier {

  RescheduleModel _reschedule;
  RescheduleModel get reschedule => _reschedule;

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

  set reschedule(RescheduleModel reschedule) {
    _reschedule=reschedule;
    notifyListeners();
  }
}

re-edit: on top of everything:

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

I'm expecting the "Consumer" to rebuild my widget, but doesn't!

I'm sure the data is there, because the widget is inside a carousel and as soon as I move it it rebuilds properly.

what am I missing? thank you

re-re-edit: here's an example of another Carousel Card where provider works quilckly and changes apply in realtime

 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(), 
Francesco Iapicca
  • 2,618
  • 5
  • 40
  • 85

2 Answers2

2

According to this article the FutureProvider does not listen for changes, it will only rebuild Consumers 1 time, when Future is complete.

The article even explains how the author tested this.

The developer of the Dart Provider package also explains the use case for FutureProvider.

Brian Ogden
  • 18,439
  • 10
  • 97
  • 176
0

Specificies the type in main.dart

void main() async {
final AppSnapshot _appSnapshot = AppSnapshot();
await _appSnapshot.load();
runApp(ChangeNotifierProvider< **AppSnapshot** >(
      builder: (context) => _appSnapshot,
      child: Initializer()));
} 
AlexPad
  • 10,364
  • 3
  • 38
  • 48