Created
December 1, 2021 02:17
-
-
Save kumamotone/3f21c6fbe17b698a122a6d58a83b90f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:hooks_riverpod/hooks_riverpod.dart'; | |
final helloWorldProvider = StateProvider((ref) => 0); | |
void main() { | |
runApp( | |
// Adding ProviderScope enables Riverpod for the entire project | |
const ProviderScope(child: MyApp()), | |
); | |
} | |
class MyApp extends HookConsumerWidget { | |
const MyApp({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context, WidgetRef ref) { | |
final value = ref.watch(helloWorldProvider.notifier); | |
final _messangerKey = GlobalKey<ScaffoldMessengerState>(); | |
return MaterialApp( | |
scaffoldMessengerKey: _messangerKey, | |
home: Scaffold( | |
body: Center( | |
child: Text("${value.state}"), | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: () { | |
value.update((state) => state + 1); | |
_messangerKey.currentState! | |
.showSnackBar(SnackBar(content: Text("${value.state}"))); | |
}, | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
2021-12-01.11.18.01.mov