flutter 显示底部导航栏抖动的对话框

k2fxgqgv  于 2023-04-07  发布在  Flutter
关注(0)|答案(1)|浏览(140)

我想在flutter中显示对话框而不是使用底部导航栏的功能。我该如何实现?

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

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

当我使用ShowDialog方法时,它说:

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.
kxeu7u2r

kxeu7u2r1#

AlertDialog可以用来显示类似于Flutter中的对话框的东西。你可以查看docs,它也包含一个你可以运行的示例。
至于你得到的错误setState() or markNeedsBuild() called during build.。这通常发生在setState()在**Widget build()**中时。此问题的常见修复方法是将setState()放置在Button的onPressed()或类似的东西中,需要一个操作来触发函数。

相关问题