命名参数 initialData 是必需的,但没有相应的参数
The named parameter initialData is required but there is no corresponding argument
在 Flutter 提供程序中,我有这个代码,它曾经可以工作,但现在在 StreamProvider<User>
处给出了这个错误。
The named parameter initialData
is required but there is no corresponding argument
User 模型没有 initialData
变量。我该如何解决这个问题?
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
),
];
StreamProvider 有一个名为 initialData 的参数。如果你想进一步,你可以检查 https://pub.dev/documentation/provider/latest/provider/StreamProvider-class.html
因此,您应该像下面几行一样传递 initialData 命名参数;
List<SingleChildStatelessWidget> uiConsumableProviders = [
StreamProvider<User>(
initialData: User(), // this line added !
create: (context) => Provider.of<AuthenticationService>(context, listen: false).user,
lazy: false
),
];
在 Flutter 提供程序中,我有这个代码,它曾经可以工作,但现在在 StreamProvider<User>
处给出了这个错误。
The named parameter
initialData
is required but there is no corresponding argument
User 模型没有 initialData
变量。我该如何解决这个问题?
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
),
];
StreamProvider 有一个名为 initialData 的参数。如果你想进一步,你可以检查 https://pub.dev/documentation/provider/latest/provider/StreamProvider-class.html
因此,您应该像下面几行一样传递 initialData 命名参数;
List<SingleChildStatelessWidget> uiConsumableProviders = [
StreamProvider<User>(
initialData: User(), // this line added !
create: (context) => Provider.of<AuthenticationService>(context, listen: false).user,
lazy: false
),
];