ValueListenableProvider<T>.value constructor

ValueListenableProvider<T>.value({
  1. Key? key,
  2. required ValueListenable<T> value,
  3. UpdateShouldNotify<T>? updateShouldNotify,
  4. Widget? child,
})

Listens to a ValueListenable and exposes its current value.

This is useful for testing purposes, to easily simular a provider update:

testWidgets('example', (tester) async {
  // Create a ValueNotifier that tests will use to drive the application
  final counter = ValueNotifier(0);

  // Mount the application using ValueListenableProvider
  await tester.pumpWidget(
    ValueListenableProvider<int>.value(
      value: counter,
      child: MyApp(),
    ),
  );

  // Tests can now simulate a provider update by updating the notifier
  // then calling tester.pump()
  counter.value++;
  await tester.pump();
});

Implementation

ValueListenableProvider.value({
  Key? key,
  required ValueListenable<T> value,
  UpdateShouldNotify<T>? updateShouldNotify,
  Widget? child,
})  : _valueListenable = value,
      _updateShouldNotify = updateShouldNotify,
      super(key: key, child: child);