我想在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.
1条答案
按热度按时间kxeu7u2r1#
AlertDialog可以用来显示类似于Flutter中的对话框的东西。你可以查看docs,它也包含一个你可以运行的示例。
至于你得到的错误
setState() or markNeedsBuild() called during build.
。这通常发生在setState()
在**Widget build()**中时。此问题的常见修复方法是将setState()放置在Button的onPressed()或类似的东西中,需要一个操作来触发函数。