断言失败错误,Flutter中没有任何日志信息

问题描述 投票:1回答:1

打开屏幕时出现以下错误,并且也没有得到适当的解释为什么这会导致问题

Getting The following assertion was thrown building LandingDetailScreen(dirty, state: _LandingDetailState#7c32d):
Assertion failed

Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=BUG.md

When the exception was thrown, this was the stack: 
#0      new MultiChildRenderObjectWidget.<anonymous closure> (package:flutter/src/widgets/framework.dart:1691:11)
#1      new MultiChildRenderObjectWidget (package:flutter/src/widgets/framework.dart:1696:8)
#2      new Flex (package:flutter/src/widgets/basic.dart:3707:8)
#3      new Column (package:flutter/src/widgets/basic.dart:4234:8)
#4      _LandingDetailState.build (package:TeamDebug/detail/LandingDetail.dart:278:26)

[这里我还附加了一些我认为会导致问题的代码

 @override
  Widget build(BuildContext context) {
    return new Scaffold(
        body: apiCall
            ? SafeArea(
                child: SingleChildScrollView(
                  child: Column(
                    children: <Widget>[
                      feedDetail.ingredients != null &&
                              feedDetail.ingredients.isNotEmpty
                          ? getScrollView(context)
                          : null,
                      Container(
                        child: SizedBox(
                          height: 10,
                        ),
                      ),
                      feedDetail.instructions != null &&
                              feedDetail.instructions.isNotEmpty
                          ? getScrollViewInstruction(context)
                          : null,
                    ],
                  ),
                ),
              );
  }

上面的代码是布局代码,可能会引起问题,但是我得到的错误并不特定于我在上面提到的整个错误以供您参考的任何行

将提供任何帮助!预先感谢。

flutter flutter-layout
1个回答
1
投票

[您有条件地返回“ null”,并且Container不允许将孩子作为“ null”,因此只需返回“ Container()”小部件而不是“ null”。

解决方案:-

@override
  Widget build(BuildContext context) {
    return new Scaffold(
        body: apiCall
            ? SafeArea(
                child: SingleChildScrollView(
                  child: Column(
                    children: <Widget>[
                      feedDetail.ingredients != null &&
                              feedDetail.ingredients.isNotEmpty
                          ? getScrollView(context)
                          : Container(),
                      Container(
                        child: SizedBox(
                          height: 10,
                        ),
                      ),
                      feedDetail.instructions != null &&
                              feedDetail.instructions.isNotEmpty
                          ? getScrollViewInstruction(context)
                          : Container(),
                    ],
                  ),
                ),
              );
  }

而且我认为这是SDK问题,因为您没有得到正确的错误,请尝试升级Flutter SDK。

© www.soinside.com 2019 - 2024. All rights reserved.