Flutter显示用户友好界面,而非异常报红

Flutter全局错误页面处理

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    ErrorWidget.builder = (FlutterErrorDetails errorDetails) {
      return getErrorWidget(context, errorDetails);//处理全局错误页面
    };
    return new MaterialApp(
      debugShowCheckedModeBanner: false, 
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: SplashPage(), //启动MainPage
    );
  }

  Widget getErrorWidget(BuildContext context, FlutterErrorDetails error) {
    return Center(
      child: Text(
        "页面加载错误,请联系管理员!",
        style: TextStyle(
          color: Colors.blue,
          fontSize: 14,
        ),
      ),
    );
  }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章