When I add flutter consumer component in flutter like this:
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,);
},
);
},
),
)
shows this error:
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.
====================================================================================================
now I am using fish-redux
to manage my flutter state, should I must using ProviderScope
? what should I do to fix this problem? this is the storiesTypeProvider
:
final storiesTypeProvider = FutureProvider.family((ref, type) async {
return await Repo.getArticles(type);
});
Bad state no element found error in flutter# firstWhere((e)=> e. age == 2); in the above code if where condition doesn't find any data matching age =2 then it will give you Bad state no element found error . for avoiding this error you can add orElse parameter which will return if element not found.
ProviderScope class Null safety. A widget that stores the state of providers. All Flutter applications using Riverpod must contain a ProviderScope at the root of their widget tree. It is done as followed: void main() { runApp( // Enabled Riverpod for the entire application ProviderScope( child: MyApp(), ), ); }
If you use flutter_riverpod. You need to add ProviderScope to the main() function. Like this:
void main() {
runApp(ProviderScope(child: MyApp()));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With