代码之家  ›  专栏  ›  技术社区  ›  Dolphin

错误状态:在颤振使用者组件中找不到ProviderScope

  •  0
  • Dolphin  · 技术社区  · 4 年前

    当我在颤振中添加颤振耗电元件时,如下所示:

    SliverPadding(
                            padding: const EdgeInsets.symmetric(vertical: 8.0),
                            sliver: Consumer(
                                  (context, read) {
                                return read(storiesTypeProvider(articleRequest)).when(
                                  loading: () {
                                    // return SliverFillRemaining(
                                    // child: Center(child: CircularProgressIndicator()));
                                    return SliverToBoxAdapter(child: Center(child: LoadingItem()));
                                  },
                                  error: (err, stack) {
                                    print(err);
                                    return SliverToBoxAdapter(
                                        child: Center(child: Text('Error: $err')));
                                  },
                                  data: (ids) {
    
    
                                    //return StoryList(ids: ids,storiesType: articleRequest.storiesType,);
                                  },
                                );
                              },
                            ),
                          )
    

    flutter: [debug] Capture from onError 'package:flutter/src/widgets/nested_scroll_view.dart': Failed assertion: line 806 pos 14: 'position.hasContentDimensions && position.hasPixels': is not true.
    flutter: [debug] Capture from onError 'package:flutter/src/widgets/nested_scroll_view.dart': Failed assertion: line 806 pos 14: 'position.hasContentDimensions && position.hasPixels': is not true.
    
    ======== Exception caught by widgets library =======================================================
    The following StateError was thrown building RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#0ac5b](state: RawGestureDetectorState#734b4(gestures: <none>, behavior: opaque)):
    Bad state: No ProviderScope found
    
    The relevant error-causing widget was: 
      SmartRefresher file:///Users/dolphin/Documents/GitHub/cruise-open/lib/src/page/home/components/homelistdefault_component/view.dart:47:22
    When the exception was thrown, this was the stack: 
    #0      ProviderStateOwnerScope.of (package:flutter_riverpod/src/framework.dart:216:7)
    #1      _ConsumerState.didChangeDependencies (package:flutter_riverpod/src/consumer.dart:107:46)
    #2      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4839:11)
    #3      ComponentElement.mount (package:flutter/src/widgets/framework.dart:4655:5)
    ...     Normal element mounting (4 frames)
    ...
    ====================================================================================================
    
    ======== Exception caught by scheduler library =====================================================
    'package:flutter/src/widgets/nested_scroll_view.dart': Failed assertion: line 806 pos 14: 'position.hasContentDimensions && position.hasPixels': is not true.
    ====================================================================================================
    
    ======== Exception caught by scheduler library =====================================================
    'package:flutter/src/widgets/nested_scroll_view.dart': Failed assertion: line 806 pos 14: 'position.hasContentDimensions && position.hasPixels': is not true.
    ====================================================================================================
    

    fish-redux 为了管理我的颤振状态,我应该使用 ProviderScope storiesTypeProvider :

    final storiesTypeProvider = FutureProvider.family((ref, type) async {
      return await Repo.getArticles(type);
    });
    
    0 回复  |  直到 4 年前
        1
  •  1
  •   Nikolay    4 年前

    如果你用颤振舱。 您需要将ProviderScope添加到main()函数中。 这样地:

    void main() {
       runApp(ProviderScope(child: MyApp()));
    }