I have this snippet:
final countProvider = StateProvider<int>((ref) {
return 0;
});
class CountWidget extends ConsumerWidget {
const CountWidget();
@override
Widget build(BuildContext context, WidgetRef ref) {
final count = ref.watch(countProvider);
return Column(
children: [
Text(count.toString()),
IconButton(
icon: const Icon(Icons.add),
onPressed: () {
ref.read(countProvider.notifier).state++;
},
),
],
);
}
}
This is a pretty simplified code, but the idea is that it is using a state provider.
I would like to write a test and verify that, after some actions, the provider is in a specific state (without relying on the UI, here I could use find.text()
, but my state could be much more complex).
I would like to access the model in my test after pumping my widget:
await tester.pumpWidget(const CountWidget());
await tester.tap();
await tester.pump();
// ... Some other actions.
final currentCountState = // ?
expect(currentCountState, 3); // For example.
How can I do that?