Home > Enterprise >  The named parameter initialData is required but there is no corresponding argument
The named parameter initialData is required but there is no corresponding argument

Time:02-08

In a Flutter provider I have this code which used to work but now gives this error at StreamProvider<User>.

The named parameter initialData is required but there is no corresponding argument

The User model doesn't have an initialData variable. How can I fix this?

List<SingleChildStatelessWidget> providers = [
  ...independentServices,
  ...dependentServices,
  ...uiConsumableProviders
];

List<SingleChildStatelessWidget> independentServices = [

  Provider(create: (_) => AppLanguage()),

  Provider(create: (_) => Api()),

];

List<SingleChildStatelessWidget> dependentServices = [

  ProxyProvider<Api, AuthenticationService>(

    update: (context, api, authenticationService) => AuthenticationService(api: api),
  
  ),
];

List<SingleChildStatelessWidget> uiConsumableProviders = [

  StreamProvider<User>(
  
    create: (context) => Provider.of<AuthenticationService>(context, listen: false).user,

    lazy: false
  
  ),

];

CodePudding user response:

StreamProvider has an initialData named argument. If you want further you can check https://pub.dev/documentation/provider/latest/provider/StreamProvider-class.html

So, you should pass initialData named argument like below lines;

List<SingleChildStatelessWidget> uiConsumableProviders = [

  StreamProvider<User>(
    initialData: User(), // this line added !
    create: (context) => Provider.of<AuthenticationService>(context, listen: false).user,
    lazy: false
  ),

];
  •  Tags:  
  • Related