Skip to content
This repository has been archived by the owner on Jun 27, 2021. It is now read-only.

setState() or markNeedsBuild() called during build. #9

Closed
webaddicted opened this issue Jan 8, 2021 · 4 comments
Closed

setState() or markNeedsBuild() called during build. #9

webaddicted opened this issue Jan 8, 2021 · 4 comments

Comments

@webaddicted
Copy link
Contributor

When I get app then it show error.

======== Exception caught by foundation library ====================================================
The following assertion was thrown while dispatching notifications for FeedProvider:
setState() or markNeedsBuild() called during build.

This _DefaultInheritedProviderScope widget cannot be marked as needing to build because the framework is already in the process of building widgets. A widget can be marked as needing to be built during the build phase only if one of its ancestors is currently building. This exception is allowed because the framework builds parent widgets before children, which means a dirty descendant will always be built. Otherwise, the framework might not visit this widget during this build phase.
The widget on which setState() or markNeedsBuild() was called was: _DefaultInheritedProviderScope
value: Instance of 'FeedProvider'
listening to value
The widget which was currently being built when the offending call was made was: BlocBuilder<NewsFeedBloc, NewsFeedState>
dirty
state: _BlocBuilderBaseState<NewsFeedBloc, NewsFeedState>#b5032
When the exception was thrown, this was the stack:
#0 Element.markNeedsBuild. (package:flutter/src/widgets/framework.dart:4328:11)
#1 Element.markNeedsBuild (package:flutter/src/widgets/framework.dart:4343:6)
#2 _InheritedProviderScopeMixin.markNeedsNotifyDependents (package:provider/src/inherited_provider.dart:269:5)
#3 ChangeNotifier.notifyListeners (package:flutter/src/foundation/change_notifier.dart:243:25)
#4 FeedProvider.setDataLoaded (package:inshort_clone/controller/provider.dart:68:5)
...
The FeedProvider sending notification was: Instance of 'FeedProvider'

@imSanjaySoni
Copy link
Owner

When I get app then it show error.

======== Exception caught by foundation library ====================================================
The following assertion was thrown while dispatching notifications for FeedProvider:
setState() or markNeedsBuild() called during build.

This _DefaultInheritedProviderScope widget cannot be marked as needing to build because the framework is already in the process of building widgets. A widget can be marked as needing to be built during the build phase only if one of its ancestors is currently building. This exception is allowed because the framework builds parent widgets before children, which means a dirty descendant will always be built. Otherwise, the framework might not visit this widget during this build phase.
The widget on which setState() or markNeedsBuild() was called was: _DefaultInheritedProviderScope
value: Instance of 'FeedProvider'
listening to value
The widget which was currently being built when the offending call was made was: BlocBuilder<NewsFeedBloc, NewsFeedState>
dirty
state: _BlocBuilderBaseState<NewsFeedBloc, NewsFeedState>#b5032
When the exception was thrown, this was the stack:
#0 Element.markNeedsBuild. (package:flutter/src/widgets/framework.dart:4328:11)
#1 Element.markNeedsBuild (package:flutter/src/widgets/framework.dart:4343:6)
#2 _InheritedProviderScopeMixin.markNeedsNotifyDependents (package:provider/src/inherited_provider.dart:269:5)
#3 ChangeNotifier.notifyListeners (package:flutter/src/foundation/change_notifier.dart:243:25)
#4 FeedProvider.setDataLoaded (package:inshort_clone/controller/provider.dart:68:5)
...
The FeedProvider sending notification was: Instance of 'FeedProvider'

Is this error coming after merging with your code?

@webaddicted
Copy link
Contributor Author

This error come when app run on device and **api call then this error
device-2021-01-08-112050
** show and at mobile end it show Some thing went wrong

@webaddicted
Copy link
Contributor Author

Hi,

Please close this issue. It's working perfectly working.
I'm facing issue because of Key is not available in at that time.
thanks

@ci30
Copy link

ci30 commented May 18, 2021

Hi guys,
This issue still persist and on real device the appbar not appear.

`══╡ EXCEPTION CAUGHT BY FOUNDATION LIBRARY ╞════════════════════════════════════════════════════════
The following assertion was thrown while dispatching notifications for FeedProvider:
setState() or markNeedsBuild() called during build.
This _DefaultInheritedProviderScope widget cannot be marked as needing to build
because the framework is already in the process of building widgets. A widget can be marked as
needing to be built during the build phase only if one of its ancestors is currently building. This
exception is allowed because the framework builds parent widgets before children, which means a
dirty descendant will always be built. Otherwise, the framework might not visit this widget during
this build phase.
The widget on which setState() or markNeedsBuild() was called was:
_DefaultInheritedProviderScope
The widget which was currently being built when the offending call was made was:
Builder

When the exception was thrown, this was the stack:
#0 Element.markNeedsBuild. (package:flutter/src/widgets/framework.dart:4210:11)
#1 Element.markNeedsBuild (package:flutter/src/widgets/framework.dart:4225:6)
#2 _InheritedProviderScopeMixin.markNeedsNotifyDependents (package:provider/src/inherited_provider.dart:269:5)
#3 ChangeNotifier.notifyListeners (package:flutter/src/foundation/change_notifier.dart:243:25)
#4 FeedProvider.setScreenController (package:seventy_mm/controller/provider.dart:117:5)
#5 _AppBaseState.initState (package:seventy_mm/view/app_base/app_base.dart:46:14)
#6 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4704:57)
#7 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4541:5)
... Normal element mounting (166 frames)
#173 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3603:14)
#174 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6170:32)
... Normal element mounting (143 frames)
#317 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3603:14)
#318 Element.updateChild (package:flutter/src/widgets/framework.dart:3355:20)
#319 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4592:16)
#320 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4739:11)
#321 Element.rebuild (package:flutter/src/widgets/framework.dart:4261:5)
#322 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2578:33)
#323 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:875:21)
#324 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:329:5)
#325 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1144:15)
#326 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1082:9)
#327 SchedulerBinding.scheduleWarmUpFrame. (package:flutter/src/scheduler/binding.dart:865:7)
(elided 11 frames from class _RawReceivePortImpl, class _Timer, dart:async, and dart:async-patch)`

Uploading Capture.JPG…

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants