Skip to content

Instantly share code, notes, and snippets.

@jetobe95
Created April 5, 2022 18:22
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 jetobe95/5589dd5415ec86dc89368118d9157570 to your computer and use it in GitHub Desktop.
Save jetobe95/5589dd5415ec86dc89368118d9157570 to your computer and use it in GitHub Desktop.
Test multiple change into a stateProvider
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(ProviderScope(child: MyApp()));
}
final countProvider = StateProvider((_) => 0);
class MyApp extends ConsumerWidget {
@override
Widget build(BuildContext context, ref) {
print("Build");
final value = ref.watch(countProvider);
return MaterialApp(
theme: ThemeData.dark().copyWith(
scaffoldBackgroundColor: darkBlue,
),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Column(
children: [
Text(value.toString()),
TextButton(
onPressed: (){
ref.read(countProvider.notifier).state++;
ref.read(countProvider.notifier).state++;
ref.read(countProvider.notifier).state++;
ref.read(countProvider.notifier).state++;
},
child: const Text(
'Incrementar',
style: TextStyle(color: Colors.white),
),
),
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment