Quero usar o pacote do provedor (4.0) no meu projeto de flutter, mas recebo o aviso / erro "Tentei usar o provedor com um subtipo de Listenable / Stream".
Minha constelação:
Eu tenho uma Api()
classe que contém a funcionalidade CRUD básica para firebase-cloudstorage.
Eu tenho uma EventService()
classe que usa a Api()
classe com um parâmetro concreto.
Para meu ponto de vista, tenho uma classe ViewModel chamada EventOverviewModel
que usa o EventService.
Minha configuração de provedor é assim:
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 = [];
Tudo parece funcionar no aplicativo, mas recebo o "Tentei usar o provedor com um subtipo de Listenable / Stream" de qualquer maneira.
Como devo alterar meu código para não receber mais essa mensagem de erro?
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 ...