Tôi muốn sử dụng gói nhà cung cấp (4.0) trong dự án rung của mình nhưng tôi nhận được cảnh báo / lỗi "Đã thử sử dụng Nhà cung cấp với một kiểu con của lỗi / cảnh báo Nghe / Phát trực tuyến".
Chòm sao của tôi:
Tôi có một Api()
lớp có chức năng CRUD cơ sở cho lưu trữ đám mây.
Tôi có một EventService()
lớp sử dụng Api()
lớp với tham số cụ thể.
Đối với quan điểm của tôi, tôi có một lớp ViewModel được gọi là EventOverviewModel
sử dụng EventService.
Cấu hình nhà cung cấp của tôi trông như thế này:
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 = [];
Mọi thứ dường như hoạt động trong ứng dụng nhưng tôi vẫn nhận được "Đã thử sử dụng Nhà cung cấp với một kiểu con của Nghe / Luồng".
Làm thế nào tôi nên thay đổi mã của tôi để không nhận được thông báo lỗi này nữa?
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 ...