Issue
Currently Im adding guest mode feature so The App that I'm developing allow user to access some feature of the app without login (guest mode).
When the user clicked profile on bottom navigation, the app will do Intent and finish(java) or pushNamedAndRemoveUntil but it crashed.
Exception has occurred. FlutterError (setState() or markNeedsBuild() called during build. This _ModalScope 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: _ModalScope-[LabeledGlobalKey<_ModalScopeState>#bfd49] The widget which was currently being built when the offending call was made was: MainPage)
Widget moveToLogin() {
Navigator.of(context)
.pushNamedAndRemoveUntil('/sign-in', (Route<dynamic> route) => false);
return Container(
child: Text("Logging in..."),
);
}
Widget body() {
switch (currentIndex) {
case 0:
return HomePage();
break;
case 1:
return ActivityPage();
break;
case 2:
return ShoppingPage();
break;
case 3:
return ChatPage();
break;
case 4:
if (user.nama_customer == "guest") {
return moveToLogin();
} else {
return ProfilePage();
}
break;
default:
return HomePage();
}
}
Solution
i've solved it with guest session. and the problem here was because of using "widget". it should be void
Answered By - Alifa Al Farizi
Answer Checked By - Marie Seifert (JavaFixing Admin)