Skip to content

Instantly share code, notes, and snippets.

@felixblaschke
Created February 14, 2021 08:39
Show Gist options
  • Save felixblaschke/8208090fdb82550adde752a74ae5b886 to your computer and use it in GitHub Desktop.
Save felixblaschke/8208090fdb82550adde752a74ae5b886 to your computer and use it in GitHub Desktop.
riverpod4.dart
var aNumber = StateProvider((_) => 0);
class SomeButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ElevatedButton(
child: Text("Click me"),
onPressed: () => buttonClicked(context),
);
}
buttonClicked(BuildContext context) {
context.read(aNumber).state = 42;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment