Skip to content

Instantly share code, notes, and snippets.

@fabiomsr
Created May 1, 2019 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabiomsr/3e347fe6551bf24af864ff7734396979 to your computer and use it in GitHub Desktop.
Save fabiomsr/3e347fe6551bf24af864ff7734396979 to your computer and use it in GitHub Desktop.
class CounterListenableProvider extends InheritedWidget {
final ValueListenable<int> counter;
CounterListenableProvider({Key key, @required this.counter, Widget child})
: super(key: key, child: child);
@override
bool updateShouldNotify(InheritedWidget oldWidget) {
return true;
}
static ValueListenable<int> of(BuildContext context) {
return (context.inheritFromWidgetOfExactType(CounterListenableProvider)
as CounterListenableProvider)
.counter;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment