【发布时间】:2020-04-18 03:57:23
【问题描述】:
我想在我的颤振项目中使用提供程序包(4.0),但我收到“尝试使用具有可侦听/流子类型的提供程序”错误/警告。
我的星座:
我有一个 Api() 类,其中包含用于 firebase-cloudstorage 的基本 CRUD 功能。
我有一个EventService()-class,它使用带有具体参数的Api()-class。
在我看来,我有一个名为 EventOverviewModel 的 ViewModel 类,它使用 EventService。
我的提供者配置如下所示:
List<SingleChildWidget> providers = [
...independentServices,
...dependentServices,
...uiConsumableProviders,
];
// Services die unabhängig von anderen sind
List<SingleChildWidget> independentServices = [
Provider<EventService>(create: (_) => EventService(api: Api('events')))
];
// Services die von anderen Services abhängig sind
List<SingleChildWidget> dependentServices = [
ProxyProvider<EventService, EventOverviewModel>(
update: (_, srvc, __) => EventOverviewModel(eventService: srvc),
)
];
List<SingleChildWidget> uiConsumableProviders = [];
一切似乎都在应用程序中工作,但无论如何我得到“尝试使用具有可侦听/流子类型的提供程序”。
我应该如何更改我的代码以不再收到此错误消息?
Running Gradle task 'assembleDebug'...
I/flutter (16553): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (16553): The following assertion was thrown building NumericProxyProvider<EventService, Void, Void, Void,
I/flutter (16553): Void, Void, EventOverviewModel>(dirty, dependencies: [InheritedProvider<EventService>], state:
I/flutter (16553): _ProxyProviderState<EventOverviewModel>#8d38d):
I/flutter (16553): Tried to use Provider with a subtype of Listenable/Stream (EventOverviewModel).
I/flutter (16553):
I/flutter (16553): This is likely a mistake, as Provider will not automatically update dependents
I/flutter (16553): when EventOverviewModel is updated. Instead, consider changing Provider for more specific
I/flutter (16553): implementation that handles the update mechanism, such as:
I/flutter (16553):
I/flutter (16553): - ListenableProvider
I/flutter (16553): - ChangeNotifierProvider
I/flutter (16553): - ValueListenableProvider
I/flutter (16553): - StreamProvider
I/flutter (16553):
I/flutter (16553): Alternatively, if you are making your own provider, consider using InheritedProvider.
I/flutter (16553):
I/flutter (16553): If you think that this is not an error, you can disable this check by setting
I/flutter (16553): Provider.debugCheckInvalidValueType to `null` in your main file:
I/flutter (16553):
I/flutter (16553): ```
I/flutter (16553): void main() {
I/flutter (16553): Provider.debugCheckInvalidValueType = null;
I/flutter (16553):
I/flutter (16553): runApp(MyApp());
I/flutter (16553): }
I/flutter (16553): ```
I/flutter (16553):
I/flutter (16553):
I/flutter (16553): The relevant error-causing widget was:
I/flutter (16553): NumericProxyProvider<EventService, Void, Void, Void, Void, Void, EventOverviewModel>
I/flutter (16553): file:///E:/Dev/flutter/.pub-cache/hosted/pub.dartlang.org/provider-3.2.0/lib/src/proxy_provider.dart:232:12
I/flutter (16553):
I/flutter (16553): When the exception was thrown, this was the stack:
I/flutter (16553): #0 Provider.debugCheckInvalidValueType.<anonymous closure>.<anonymous ...
【问题讨论】: