gpt4 book ai didi

flutter - 状态错误 : No ProviderScope found in flutter consumer component

转载 作者:行者123 更新时间:2023-12-04 01:08:52 25 4
gpt4 key购买 nike

当我像这样在 flutter 中添加 flutter 消费者组件时:

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管理我的 flutter 状态,我是否必须使用 ProviderScope ?我该怎么做才能解决这个问题?这是 storiesTypeProvider :
final storiesTypeProvider = FutureProvider.family((ref, type) async {
return await Repo.getArticles(type);
});

最佳答案

如果您使用 flutter_riverpod。
您需要将 ProviderScope 添加到 main() 函数。
像这样:

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

关于flutter - 状态错误 : No ProviderScope found in flutter consumer component,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65462638/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com