在构建抖动期间调用setState()或markNeedsBuild()

时间:2019-03-16 17:07:47

标签: dart flutter

我有两个屏幕。当我将第一个屏幕导航到第二个屏幕时,显示模式底部工作表必须显示在第二个屏幕中。我是这样的: 在第一个屏幕中:

new FlatButton(
    onPressed: (){
       Navigator.pushReplacement(
          context,
          new MaterialPageRoute(builder: (context) => secondScreen()),
       );
    },
    child: new Text('Click'),
)

在第二个屏幕中:

class secondScreen extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
       bottomSheet: _showModalSheet(context),
    );
  }
}
_showModalSheet(BuildContext context) {
  showModalBottomSheet(
    context: context,
    builder: (BuildContext context){
      return new Container(
       ......
      );
    }
  );
 }

但是显示错误:

I/flutter (21342): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (21342): The following assertion was thrown building ExploreOnboarding(dirty):
I/flutter (21342): setState() or markNeedsBuild() called during build.
I/flutter (21342): This Overlay widget cannot be marked as needing to build because the framework is already in the
I/flutter (21342): process of building widgets. A widget can be marked as needing to be built during the build phase
I/flutter (21342): only if one of its ancestors is currently building. This exception is allowed because the framework
I/flutter (21342): builds parent widgets before children, which means a dirty descendant will always be built.
I/flutter (21342): Otherwise, the framework might not visit this widget during this build phase.
I/flutter (21342): The widget on which setState() or markNeedsBuild() was called was:
I/flutter (21342):   Overlay-[LabeledGlobalKey<OverlayState>#1c3f3](state: OverlayState#c3193(tickers: tracking 1
I/flutter (21342):   ticker, entries: [OverlayEntry#51a27(opaque: true; maintainState: false),
I/flutter (21342):   OverlayEntry#8e935(opaque: false; maintainState: true), OverlayEntry#c3e6e(opaque: false;
I/flutter (21342):   maintainState: false), OverlayEntry#54fff(opaque: false; maintainState: true),
I/flutter (21342):   OverlayEntry#6812d(opaque: false; maintainState: false), OverlayEntry#85b14(opaque: false;
I/flutter (21342):   maintainState: true), OverlayEntry#cb7eb(opaque: false; maintainState: false),
I/flutter (21342):   OverlayEntry#6d2e6(opaque: false; maintainState: true)]))

0 个答案:

没有答案
相关问题