错误状态:尝试读取在创建其值期间抛出的提供程序在创建 Future<List<Place>> ================================================ ============当我这样导航时没问题MultiProvider -> MaterialApp -> DesiredScreen================================================ ============但

问题描述

我知道很多人问这个问题,但我没有找到任何答案,所以这有点不同

我正面临这个错误。当我直接从主页调用 Desired Screen 时它工作正常,但是当我从另一个屏幕导航 DesiredScreen 时,它显示错误。我用地图给你解释

================================================ ============

当我这样导航时没问题

MultiProvider -> MaterialApp -> DesiredScreen

================================================ ============

但是当我浏览它时,它显示了这个 BadState 错误

MultiProvider -> MaterialApp -> HomePage -> DesiredScreen

================================================ ============

更新的问题

当我把条件放在主类小部件中时

count == 1 ? DesiredScreen() : HomePage()

显示错误,但如果我从其他屏幕导航到 DesiredScreen,它不会显示错误

================================================ ============

代码

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
    ...
    ════════════════════════════════════════════════════════════════════════════════

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)