抛出另一个异常: Instance of 'ErrorSummary' when performing platform check Flutter web

Another exception was thrown: Instance of 'ErrorSummary' when performing platform check Flutter web

我有底部导航栏,可以在两个屏幕 BookingsScreenOpeningTimesScreen 之间切换。我的问题是 OpeningTimesScreen UI 第一次没有正确加载。如果再次点击它的图标或者如果我先 select BookingsScreen 然后 select 它会加载。 由于完整的 UI 非常拥挤,有 28 个文本字段和 14 个开关,我只是将它减少到只有一个文本字段并做了一些测试。 似乎问题出在三元组中声明的文本字段,我在应用程序在网络和平板电脑上运行时所做的事情..

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

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

如果我在扩展小部件中声明它 UI 仍然可以正确构建。

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

如果我在没有签入平台的情况下声明它 UI 仍然可以正确构建。

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 图标,它就会正常加载。

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 控制台我看到 Another exception was thrown: Instance of 'ErrorSummary'js_primitives.dart:47 link。

点击它打开一个标签:

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)

..我在应用程序启动时也有另一个错误,我不知道它们是否相关..

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

我可以检查什么来确定是什么原因造成的? 一如既往,非常感谢您的时间和帮助。

我也把整个class:

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 库,所以它抛出异常..

添加第一个检查 kISWeb 解决了它。 我实际上认为 Platform.isIOS 检查失败也会自动在网络的另一个选项中展开,但它需要自己的检查..

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);
                              },
                            ),
                ),

希望对其他人有所帮助。 干杯