【问题标题】:Another exception was thrown: Instance of 'ErrorSummary' when performing platform check Flutter web引发了另一个异常:执行平台检查时出现“ErrorSummary”实例 Flutter web
【发布时间】:2020-09-24 15:40:04
【问题描述】:

我有底部导航栏,可以在BookingsScreenOpeningTimesScreen 两个屏幕之间切换。我的问题是OpeningTimesScreen UI 第一次没有正确加载。如果再次点击它的图标或者我先选择BookingsScreen 然后选择它,它会加载。 由于完整的 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 控制台中,我看到了带有 js_primitives.dart:47 链接的 Another exception was thrown: Instance of 'ErrorSummary'

点击它会打开一个标签:

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

【问题讨论】:

    标签: flutter-web


    【解决方案1】:

    找到问题了。

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

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

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

    希望它可以帮助其他人。 干杯

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-21
      • 1970-01-01
      • 2021-11-23
      • 1970-01-01
      • 2019-01-25
      • 1970-01-01
      • 2021-04-29
      • 2021-02-04
      相关资源
      最近更新 更多