Home > Net >  how to override a provider with a Mock for ChangeNotifierProvider in Riverpod?
how to override a provider with a Mock for ChangeNotifierProvider in Riverpod?

Time:06-14

I am using flutter_riverpod: ^1.0.3

I am trying to write a widget test. I have ChangeNotifierProvider like the code below

final customerDataControllerProvider = ChangeNotifierProvider<CustomerDataController>((ref) {
  return CustomerDataController();
});

and here is the CustomerDataController class

class CustomerDataController with ChangeNotifier {
  //
}

I am using enter image description here

The argument type 'MockCustomerDataController' can't be assigned to the parameter type 'ChangeNotifierProvider'.

I am confused, how to 'replace' my CustomerDataController class to my Mock class ?

CodePudding user response:

Try overrideWithValue, see Testing.

  • Related