FilledStacks / provider_architecture

A set of widgets to help with the implementation of the Provider architecture as shown by FilledStacks
86 stars 15 forks source link

Turn off Listen for ProviderWidget #4

Closed FilledStacks closed 4 years ago

FilledStacks commented 4 years ago

We have identified in some cases that we don't want to rebuild a widget when notifyListeners is called. This stems from the need to use a ViewModel in a widget, but that widget does not make use of the state of the ViewModel. Since the ViewModel is not using the state a rebuild is a wasted resource.

A solution to this would be to add a construction optional parameter to the ProviderWidget called listen. This property will be a boolean with a default value true. We will then use this property in the Provider element where we use Provider.of(context) and pass the property to the listen property on the .of call.

FilledStacks commented 4 years ago

See Gist by Ryan here that demonstrates the issue

VictorUvarov commented 4 years ago

I think you might have to create another widget for this to work. (Probably a better way) Something like ProviderWidget.withoutListener or something. Otherwise, if you are using Provider.of<Model>(context, listen: false).someFunction() you probably know you have the model above in the widget tree.

FilledStacks commented 4 years ago

It wouldn’t be fixed to listen false. The value will be passed in through the constructor. Only the widgets where you want to disable listening will pass listen:false to the super constructor. It’ll be true by default.

From: Victormailto:notifications@github.com Sent: Thursday, 05 December 2019 23:26 To: FilledStacks/provider_architecturemailto:provider_architecture@noreply.github.com Cc: Dane Mackiermailto:dane.mackier@outlook.com; Authormailto:author@noreply.github.com Subject: Re: [FilledStacks/provider_architecture] Turn off Listen for ProviderWidget (#4)

I think you might have to create another widget for this to work. (Probably a better way) Something like ProviderWidget.withoutListener or something. Otherwise, if you are using Provider.of(context, listen: false).someFunction() you probably know you have the model above in the widget tree.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/FilledStacks/provider_architecture/issues/4?email_source=notifications&email_token=AA3M72WOFKT6RIC4S7WISWLQXFWYRA5CNFSM4JTG3ZIKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEGCGQ7Y#issuecomment-562325631, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AA3M72TYIHR7DW6IZ7IIB7TQXFWYRANCNFSM4JTG3ZIA.