BilalShahid13 / PersistentBottomNavBar

A highly customizable persistent bottom navigation bar for Flutter
BSD 3-Clause "New" or "Revised" License
507 stars 371 forks source link

Get setState() or markNeedsBuild() called during build for PersistentBottomNavBar who is not ready before children widget #310

Open kAgotsi opened 1 year ago

kAgotsi commented 1 year ago

Hello,

I'm getting the issue `======== Exception caught by widgets library ======================================================= The following assertion was thrown building EmployeesAndCompaniesTab(dirty): setState() or markNeedsBuild() called during build.

This Obx 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: Obx has builder dirty state: _ObxState#14ad0 The widget which was currently being built when the offending call was made was: EmployeesAndCompaniesTab dirty The relevant error-causing widget was: EmployeesAndCompaniesTab EmployeesAndCompaniesTab:file:///search_screen.dart:98:19 When the exception was thrown, this was the stack:

0 Element.markNeedsBuild. (package:flutter/src/widgets/framework.dart:4476:11)

1 Element.markNeedsBuild (package:flutter/src/widgets/framework.dart:4491:6)

2 State.setState (package:flutter/src/widgets/framework.dart:1129:15)

3 _ObxState._updateTree (package:get/get_state_manager/src/rx_flutter/rx_obx_widget.dart:41:7)

4 GetStream._notifyData (package:get/get_rx/src/rx_stream/get_stream.dart:47:21)

5 GetStream.add (package:get/get_rx/src/rx_stream/get_stream.dart:97:5)

6 NotifyManager.addListener. (package:get/get_rx/src/rx_types/rx_core/rx_impl.dart:158:40)

7 GetStream._notifyData (package:get/get_rx/src/rx_stream/get_stream.dart:47:21)

8 GetStream.add (package:get/get_rx/src/rx_stream/get_stream.dart:97:5)

9 RxObjectMixin.refresh (package:get/get_rx/src/rx_types/rx_core/rx_impl.dart:29:13)

10 RxList.length= (package:get/get_rx/src/rx_types/rx_iterables/rx_list.dart:100:5)

11 ListMixin.clear (dart:collection/list.dart:342:10)

12 EmployeesAndCompaniesController.onSearch (package:/employees_and_companies_controller.dart:140:49)

13 EmployeesAndCompaniesTab.build (package:/employees_and_companies_tab.dart:31:16)

14 _GetCache.build (package:get/get_state_manager/src/simple/get_view.dart:103:20)

15 GetWidgetCacheElement.build (package:get/get_state_manager/src/simple/get_widget_cache.dart:29:27)

16 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4806:15)

17 GetWidgetCacheElement.performRebuild (package:get/get_state_manager/src/simple/get_widget_cache.dart:35:11)

18 Element.rebuild (package:flutter/src/widgets/framework.dart:4529:5)

19 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2659:19)

20 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:891:21)

21 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:370:5)

22 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1146:15)

23 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1083:9)

24 SchedulerBinding.scheduleWarmUpFrame. (package:flutter/src/scheduler/binding.dart:864:7)

(elided 4 frames from class _RawReceivePortImpl, class _Timer, and dart:async-patch)`

When I use
PersistentNavBarNavigator.pushNewScreen( context, screen: SearchScreen(), withNavBar: true, // OPTIONAL VALUE. True by default. pageTransitionAnimation: PageTransitionAnimation.cupertino, );

to navigate to previous screen. After investigation the PersistentBottomNavBar who is parent widget ho contain other widget is not ready before children so I raised error. Who can I resolve this ?

Thanks you for help