引发了另一个异常:执行平台检查Flutter Web时出现"ErrorSummary"实例 [英] Another exception was thrown: Instance of 'ErrorSummary' when performing platform check Flutter web

查看:278
本文介绍了引发了另一个异常:执行平台检查Flutter Web时出现"ErrorSummary"实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有底部导航栏,可在两个屏幕BookingsScreenOpeningTimesScreen之间切换.我的问题是OpeningTimesScreen UI第一次无法正确加载.如果再次点按其图标,或者如果我先选择BookingsScreen然后选择它,它确实会加载. 由于完整的UI包含28个文本字段和14个开关,因此我只将其缩减为仅一个文本字段并进行了一些测试. 看来问题出在三元内部声明的文本字段,我在应用程序在Web和平板电脑上运行时所做的事情.

I have bottom navigation bar that switches between two screens BookingsScreen and OpeningTimesScreen. My problem is that OpeningTimesScreen UI doesn't load properly the first time. It does load if tap on its icon again or if I select BookingsScreen first and then select it. As the full UI is quite crowded with 28 textfields and 14 switches, I just reduced it to only one textfield and did some tests. It seems that the problem is with textfield declared inside a ternary, thing that I do as the app runs on web and on tablets..

如果我声明文本字段为Column的直接子UI正确构建.

If I declare the textfield as Column's direct child UI builds correctly.

TextField(
                keyboardType: TextInputType.numberWithOptions(),
                controller: monMorOp,
                onChanged: (value) {
                  monMorOp.text = validateTimeFormat(value);
                },
              ),

如果我在扩展的小部件中声明它,UI仍会正确构建.

If I declare it in an expanded widget UI still builds correctly.

Expanded(
                flex: 1,
                child: TextField(
                  keyboardType: TextInputType.numberWithOptions(),
                  controller: monMorOp,
                  onChanged: (value) {
                    monMorOp.text = validateTimeFormat(value);
                  },
                ),
              ),

如果我在没有签入的情况下声明它,则平台UI仍会正确构建.

If I declare it without checkin platform UI still builds correctly.

Expanded(
                flex: 1,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  mainAxisSize: MainAxisSize.max,
                  //title row
                  children: <Widget>[
                    Expanded(
                      flex: 2,
                      child: Text(
                        AppLocalizations.instance.text('Monday'),
                        style: TextStyle(color: Colors.white, fontSize: 20),
                      ),
                    ),
                    SizedBox(
                      width: 20,
                    ),
                    Expanded(
                      flex: 2,
                      child: TextField(
                        keyboardType: TextInputType.numberWithOptions(),
                        controller: monMorOp,
                        onChanged: (value) {
                          monMorOp.text = validateTimeFormat(value);
                        },
                      ),
                    ),
                  ],
                ),
              ),

当我执行平台检查时,仅在首次加载时出现错误和灰屏.再次点击BottomNavigationBar图标,它会正常加载.

When I do perform the platform checking then I get the error and a grey screen at first load only. Once you tap on the BottomNavigationBar icon again it loads fine.

Expanded(
                flex: 1,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  mainAxisSize: MainAxisSize.max,
                  //title row
                  children: <Widget>[
                    Expanded(
                      flex: 2,
                      child: Text(
                        AppLocalizations.instance.text('Monday'),
                        style: TextStyle(color: Colors.white, fontSize: 20),
                      ),
                    ),
                    SizedBox(
                      width: 20,
                    ),
                    Expanded(
                      flex: 2,
                      child: Platform.isIOS
                          ? CupertinoTextField(
                              keyboardType: TextInputType.numberWithOptions(),
                              controller: monMorOp,
                              onChanged: (value) {
                                monMorOp.text = validateTimeFormat(value);
                              },
                            )
                          : TextField(
                              keyboardType: TextInputType.numberWithOptions(),
                              controller: monMorOp,
                              onChanged: (value) {
                                monMorOp.text = validateTimeFormat(value);
                              },
                            ),
                    ),

从Chrome控制台中,我看到带有js_primitives.dart:47链接的Another exception was thrown: Instance of 'ErrorSummary'.

From Chrome console I see the Another exception was thrown: Instance of 'ErrorSummary' with js_primitives.dart:47 link.

单击它会打开一个带有以下内容的标签:

Clicking it opens a tab with this:

Could not load content for org-dartlang-sdk:///lib/_internal/js_runtime/lib/js_primitives.dart (HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME)

..应用启动时我也遇到另一个错误,我不知道它们是否相关.

..I also have another error when app starts and I don't know if they're related..

favicon.ico:1 GET http://localhost:5000/favicon.ico 404 (Not Found)

我可以检查什么原因? 一如既往,非常感谢您的时间和帮助.

What can I check to see what's causing it? As always thank you very much for your time and help.

我也把整个课都放了:

class OpeningTimesScreen extends StatefulWidget {
  final FixitUser user;
  final LatLng coordinates;
  final String cityDb;
  final String regionDb;
  final String countryDb;
  const OpeningTimesScreen(
      {Key key,
      @required this.user,
      @required this.coordinates,
      @required this.cityDb,
      @required this.regionDb,
      @required this.countryDb})
      : super(key: key);

  @override
  _OpeningTimesScreenState createState() => _OpeningTimesScreenState();
}

// TODO expanded causes error : Another exception was thrown: Instance of 'ErrorSummary'
class _OpeningTimesScreenState extends State<OpeningTimesScreen> {
  TextEditingController monMorOp = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return BlocProvider<OpeningTimesBloc>(
      lazy: false,
      create: (BuildContext context) =>
          OpeningTimesBloc()..add(LoadOpeningTimes(widget.user)),
      child: BlocConsumer<OpeningTimesBloc, OpeningTimesState>(
        listener: (BuildContext context, OpeningTimesState state) {},
        builder: (context, state) => Container(
          color: Colors.black54,
          padding: EdgeInsets.symmetric(horizontal: 100, vertical: 50),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: <Widget>[
              //                                                              TODO titles
              Expanded(
                flex: 1,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  mainAxisSize: MainAxisSize.max,
                  children: <Widget>[
                    Expanded(
                      flex: 2,
                      child: Text(
                        '',
                        style: TextStyle(color: Colors.white, fontSize: 20),
                      ),
                    ),
                    SizedBox(
                      width: 20,
                    ),
                    Expanded(
                      flex: 2,
                      child: Text(
                        AppLocalizations.instance.text('Opening'),
                        textAlign: TextAlign.center,
                        style: TextStyle(color: Colors.white, fontSize: 20),
                      ),
                    ),
                    SizedBox(
                      width: 20,
                    ),
                    Expanded(
                      flex: 2,
                      child: Text(
                        AppLocalizations.instance.text('Closing'),
                        textAlign: TextAlign.center,
                        style: TextStyle(color: Colors.white, fontSize: 20),
                      ),
                    ),
                    SizedBox(
                      width: 20,
                    ),
                    Expanded(
                      flex: 1,
                      child: Text(
                        AppLocalizations.instance.text('Active'),
                        textAlign: TextAlign.center,
                        style: TextStyle(color: Colors.white, fontSize: 20),
                      ),
                    ),
                    SizedBox(
                      width: 40,
                    ),
                    Expanded(
                      flex: 2,
                      child: Text(
                        AppLocalizations.instance.text('Opening'),
                        textAlign: TextAlign.center,
                        style: TextStyle(color: Colors.white, fontSize: 20),
                      ),
                    ),
                    SizedBox(
                      width: 20,
                    ),
                    Expanded(
                      flex: 2,
                      child: Text(
                        AppLocalizations.instance.text('Closing'),
                        textAlign: TextAlign.center,
                        style: TextStyle(color: Colors.white, fontSize: 20),
                      ),
                    ),
                    SizedBox(
                      width: 20,
                    ),
                    Expanded(
                      flex: 1,
                      child: Text(
                        AppLocalizations.instance.text('Active'),
                        textAlign: TextAlign.center,
                        style: TextStyle(color: Colors.white, fontSize: 20),
                      ),
                    ),
                  ],
                ),
              ),

              // TODO UI builds without a problem
//              TextField(
//                keyboardType: TextInputType.numberWithOptions(),
//                controller: monMorOp,
//                onChanged: (value) {
//                  monMorOp.text = validateTimeFormat(value);
//                },
//              ),

              // TODO UI builds without a problem
//              Expanded(
//                flex: 1,
//                child: TextField(
//                  keyboardType: TextInputType.numberWithOptions(),
//                  controller: monMorOp,
//                  onChanged: (value) {
//                    monMorOp.text = validateTimeFormat(value);
//                  },
//                ),
//              ),
              // TODO UI builds without a problem
              //                                                              TODO monday
//              Expanded(
//                flex: 1,
//                child: Row(
//                  mainAxisAlignment: MainAxisAlignment.center,
//                  mainAxisSize: MainAxisSize.max,
//                  //title row
//                  children: <Widget>[
//                    Expanded(
//                      flex: 2,
//                      child: Text(
//                        AppLocalizations.instance.text('Monday'),
//                        style: TextStyle(color: Colors.white, fontSize: 20),
//                      ),
//                    ),
//                    SizedBox(
//                      width: 20,
//                    ),
//                    Expanded(
//                      flex: 2,
//                      child: TextField(
//                        keyboardType: TextInputType.numberWithOptions(),
//                        controller: monMorOp,
//                        onChanged: (value) {
//                          monMorOp.text = validateTimeFormat(value);
//                        },
//                      ),
//                    ),
//                  ],
//                ),
//              ),

              // TODO UI build problem
              //                                                              TODO monday
              Expanded(
                flex: 1,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  mainAxisSize: MainAxisSize.max,
                  //title row
                  children: <Widget>[
                    Expanded(
                      flex: 2,
                      child: Text(
                        AppLocalizations.instance.text('Monday'),
                        style: TextStyle(color: Colors.white, fontSize: 20),
                      ),
                    ),
                    SizedBox(
                      width: 20,
                    ),
                    Expanded(
                      flex: 2,
                      child: Platform.isIOS
                          ? CupertinoTextField(
                              keyboardType: TextInputType.numberWithOptions(),
                              controller: monMorOp,
                              onChanged: (value) {
                                monMorOp.text = validateTimeFormat(value);
                              },
                            )
                          : TextField(
                              keyboardType: TextInputType.numberWithOptions(),
                              controller: monMorOp,
                              onChanged: (value) {
                                monMorOp.text = validateTimeFormat(value);
                              },
                            ),
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

推荐答案

发现了问题.

首先要检查的是dart.io库,它会引发异常.

As the first thing it get checked is a dart.io library it throws an exception..

添加第一个检查kISWeb解决了它. 我实际上以为通过Platform.isIOS检查失败的情况也会自动出现在Web的另一个选项中,但是它需要自己进行检查..

Adding a first check kISWeb solved it. I actually thought that failing the Platform.isIOS check automatically unfolded in the other option for web as well, but it needs its own check ..

Expanded(
                  flex: 2,
                  child: kIsWeb
                      ? TextField(
                          keyboardType: TextInputType.numberWithOptions(),
                          controller: monMorOp,
                          onChanged: (value) {
                            monMorOp.text = validateTimeFormat(value);
                          },
                        )
                      : Platform.isIOS
                          ? CupertinoTextField(
                              keyboardType: TextInputType.numberWithOptions(),
                              controller: monMorOp,
                              onChanged: (value) {
                                monMorOp.text = validateTimeFormat(value);
                              },
                            )
                          : TextField(
                              keyboardType: TextInputType.numberWithOptions(),
                              controller: monMorOp,
                              onChanged: (value) {
                                monMorOp.text = validateTimeFormat(value);
                              },
                            ),
                ),

希望它对其他人有帮助. 干杯

Hope it helps others. Cheers

这篇关于引发了另一个异常:执行平台检查Flutter Web时出现"ErrorSummary"实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆