我正面临这个错误。当我直接从主页调用 Desired Screen 时它工作正常,但是当我从另一个屏幕导航 DesiredScreen 时,它显示此错误。我用地图给你解释
count == 1 ? DesiredScreen() : HomePage()
Widget build(BuildContext context) {
return MultiProvider(
providers: [
FutureProvider(
create: (_) => locatorService.getLocation(),
initialData: null,
),
FutureProvider(
initialData: null,
create: (_) {
ImageConfiguration imageConfiguration =
createLocalImageConfiguration(context);
return BitmapDescriptor.fromAssetImage(
imageConfiguration, 'assets/images/fire.png');
},
),
ProxyProvider2<Position, BitmapDescriptor, Future<List<Place>>>(
update: (_, position, icon, places) {
return (position != null)
? placeService.getPlaces(
position.latitude, position.longitude, icon)
: null;
})
],
child: MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primaryColor: Colors.blueAccent,
),
home: DesiredScreen(),
),
);
════════ Exception caught by widgets library ═══════════════════════════════════
The following StateError was thrown building GoogleMapView(dirty, dependencies: [_InheritedProviderScope<Position>, _InheritedProviderScope<Future<List<Place>>>], state: _GoogleMapViewState#878c8):
Bad state: Tried to read a provider that threw during the creation of its value.
The exception occurred during the creation of type Future<List<Place>>.
The relevant error-causing widget was
GoogleMapView
lib\screens\home.dart:7
When the exception was thrown, this was the stack
#0 _CreateInheritedProviderState.value
package:provider/src/inherited_provider.dart:661
#1 _InheritedProviderScopeElement.value
package:provider/src/inherited_provider.dart:544
#2 Provider.of
package:provider/src/provider.dart:289
#3 _GoogleMapViewState.build
package:vibecheck/screens/google_map_view.dart:39
#4 StatefulElement.build
package:flutter/…/widgets/framework.dart:4612
...
════════════════════════════════════════════════════════════════════════════════