0

I want to show Dialog instead of function using bottom navigation bar in flutter.How can I implement that?

 @override
      Widget build(BuildContext context) {
      Widget child = Container();
      switch(_selectedIndex) {
        case 0:
          child = function_1();
          print("done");
          break;

        case 1:
          child = function_1();
          break;
      }

When I use ShowDialog method It says:

The following assertion was thrown building ServerGrid(dirty; state: _ServerGridState#59211289()):
I/flutter (14351): setState() or markNeedsBuild() called during build.
I/flutter (14351): This Overlay widget cannot be marked as needing to build because the framework is already in the
I/flutter (14351): process of building widgets. A widget can be marked as needing to be built during the build phase
I/flutter (14351): only if one of its ancestors is currently building. This exception is allowed because the framework
I/flutter (14351): builds parent widgets before children, which means a dirty descendant will always be built.
I/flutter (14351): Otherwise, the framework might not visit this widget during this build phase.
Axen_Rangs
  • 261
  • 7
  • 19

1 Answers1

0

AlertDialog can be used to display something similar to a Dialog box in Flutter. You can check out the docs that also includes a sample that you can run.

As for the error setState() or markNeedsBuild() called during build. that you're getting. This usually occurs when setState() is in Widget build(). A common fix for this issue is to place setState() inside a Button's onPressed() or something similar that requires an action to trigger the function.

Omatt
  • 8,564
  • 2
  • 42
  • 144