dart - RenderCustomMultiChildLayoutBox 对象在布局错误期间被赋予无限大小

标签 dart flutter

当我尝试加载 LessonPage 时,我不断收到上述错误。发生的事情是我有一个 RootPage 检查用户是否登录,如果他是 RootPage 将显示 LessonPage 但如果他不是,它将显示 LoginScreen,当用户登录时,将调用回调函数到 RootPage _onLoggedIn() 以便将页面切换到 LessonPage

更新:我发现当我加载应用程序时也会记录错误(即应用程序打开到 LoginScreen),但是我看到的是我的登录屏幕而不是空白屏幕.我在下面附加了我的 LoginScreen 代码以供引用

根页面:

class RootPage extends StatefulWidget {
  RootPage({this.auth});

  final BaseAuth auth;

  @override
  State<StatefulWidget> createState() => new _RootPageState();
}

enum AuthStatus {
  NOT_DETERMINED,
  NOT_LOGGED_IN,
  LOGGED_IN,
}

class _RootPageState extends State<RootPage> {
  AuthStatus authStatus = AuthStatus.NOT_DETERMINED;
  String _userId = "";

  @override
  void initState() {
    super.initState();
    widget.auth.getCurrentUser().then((user) {
      setState(() {
        if (user != null) {
          _userId = user?.uid;
        }
        authStatus =
            user?.uid == null ? AuthStatus.NOT_LOGGED_IN : AuthStatus.LOGGED_IN;
      });
    });
  }

  void _onLoggedIn() {
    widget.auth.getCurrentUser().then((user){
      setState(() {
        _userId = user.uid.toString();
      });
    });
    setState(() {
      authStatus = AuthStatus.LOGGED_IN;

    });
  }

  void _onSignedOut() {
    setState(() {
      authStatus = AuthStatus.NOT_LOGGED_IN;
      _userId = "";
    });
  }

  Widget _buildWaitingScreen() {
    return Scaffold(
      body: Container(
        alignment: Alignment.center,
        child: 
        ColorLoader5(
          dotOneColor: Colors.blueGrey[600],
          dotTwoColor: Colors.blueGrey[700],
          dotThreeColor: Colors.blueGrey[800],
          dotType: DotType.circle,
          dotIcon: Icon(Icons.adjust),
          duration: Duration(seconds: 1),      
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    switch (authStatus) {
      case AuthStatus.NOT_DETERMINED:
        return _buildWaitingScreen();
        break;
      case AuthStatus.NOT_LOGGED_IN:
        return new LoginScreen(
          auth: widget.auth,
          onSignedIn: _onLoggedIn,
        );
        break;
      case AuthStatus.LOGGED_IN:
        if (_userId.length > 0 && _userId != null) {
          return new Container(child: SingleChildScrollView(child: LessonPage(
            title: LESSON_PAGE_TITLE,
            userId: _userId,
            auth: widget.auth,
            onSignedOut: _onSignedOut,
          )));
        } else return _buildWaitingScreen();
        break;
      default:
        return _buildWaitingScreen();
    }
  }
}

类(class)页面:

class LessonPage extends StatefulWidget {
  LessonPage({Key key, this.auth, this.userId, this.onSignedOut, this.title}) : super(key: key);

  final String title;

  final BaseAuth auth;
  final VoidCallback onSignedOut;
  final String userId;

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

class _LessonPageState extends State<LessonPage> {
  List lessons;

  @override
  void initState() {
    lessons = StaticMethods.getLessons();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    ListTile makeListTile(Lesson lesson) => ListTile(
          contentPadding:
              EdgeInsets.symmetric(horizontal: 20.0, vertical: 10.0),
          leading: Container(
            padding: EdgeInsets.only(right: 12.0),
            decoration: new BoxDecoration(
                border: new Border(
                    right: new BorderSide(width: 1.0, color: Colors.white24))),
            child: IconButton(
              icon: Icon(Icons.file_download, color: Colors.white),
              onPressed: (){},
            ),
          ),
          title: Text(
            lesson.title,
            style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
          ),

          subtitle: Row(
            children: <Widget>[
              Expanded(
                  flex: 1,
                  child: Container(
                    child: LinearProgressIndicator(
                        backgroundColor: Color.fromRGBO(209, 224, 224, 0.2),
                        value: lesson.indicatorValue,
                        valueColor: AlwaysStoppedAnimation(Colors.green)),
                  )),
              Expanded(
                flex: 4,
                child: Padding(
                    padding: EdgeInsets.only(left: 10.0),
                    child: Text(lesson.level,
                        style: TextStyle(color: Colors.white))),
              )
            ],
          ),
          trailing:
              Icon(Icons.keyboard_arrow_right, color: Colors.white, size: 30.0),
          onTap: () {
            Navigator.push(
                context,
                MaterialPageRoute(
                    builder: (context) => DetailPage(lesson: lesson)));
          },
        );

    Card makeCard(Lesson lesson) => Card(
          elevation: 8.0,
          margin: new EdgeInsets.symmetric(horizontal: 10.0, vertical: 6.0),
          child: Container(
            decoration: BoxDecoration(color: Color.fromRGBO(64, 75, 96, .9)),
            child: makeListTile(lesson),
          ),
        );

    final makeBody = Container(
      child: ListView.builder(
        scrollDirection: Axis.vertical,
        shrinkWrap: true,
        itemCount: lessons.length,
        itemBuilder: (BuildContext context, int index) {
          return makeCard(lessons[index]);
        },
      ),
    );

    final makeBottom = Container(
      height: 55.0,
      child: BottomAppBar(
        color: Color.fromRGBO(58, 66, 86, 1.0),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: <Widget>[
            IconButton(
              icon: Icon(Icons.school, color: Colors.white),
              onPressed: () => StaticMethods.goToWidget(context, new LessonPage(title: LESSON_PAGE_TITLE)),
            ),
            IconButton(
              icon: Icon(Icons.flight_takeoff, color: Colors.white),
              onPressed: () {},
            ),
            IconButton(
              icon: Icon(Icons.account_box, color: Colors.white),
              onPressed: () {},
            )
          ],
        ),
      ),
    );
    final topAppBar = AppBar(
      elevation: 0.1,
      backgroundColor: Color.fromRGBO(58, 66, 86, 1.0),
      title: Text(widget.title),
      automaticallyImplyLeading: false,
    );

    return Scaffold(
      backgroundColor: Color.fromRGBO(58, 66, 86, 1.0),
      appBar: topAppBar,
      body: makeBody,
      bottomNavigationBar: makeBottom,
    );
  }
}

登录屏幕容器:

  Widget OptionPage() {
    return new Container(
      height: MediaQuery.of(context).size.height,
      decoration: BoxDecoration(
        color: Color.fromRGBO(58, 66, 86, 1.0),
        image: DecorationImage(
          colorFilter: new ColorFilter.mode(
              Colors.black.withOpacity(0.1), BlendMode.dstATop),
          image: AssetImage('assets/images/drones.jpg'),
          fit: BoxFit.cover,
        ),
      ),
      child: new Column(
        children: <Widget>[
          Container(
            padding: EdgeInsets.only(top: 250.0),
            child: Center(
              child: Icon(
                Icons.school,
                color: Colors.white,
                size: 40.0,
              ),
            ),
          ),
          Container(
            padding: EdgeInsets.only(top: 20.0),
            child: new Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text(
                  LOGIN_SCREEN_TITLE,
                  style: TextStyle(
                    color: Colors.white,
                    fontSize: 20.0,
                  ),
                ),
              ],
            ),
          ),
          new Container(
            width: MediaQuery.of(context).size.width,
            margin: const EdgeInsets.only(left: 30.0, right: 30.0, top: 150.0),
            alignment: Alignment.center,
            child: new Row(
              children: <Widget>[
                new Expanded(
                  child: new OutlineButton(
                    shape: new RoundedRectangleBorder(
                        borderRadius: new BorderRadius.circular(30.0)),
                    color: Color.fromRGBO(58, 66, 86, 1.0),
                    highlightedBorderColor: Colors.white,
                    onPressed: () => gotoSignup(),
                    child: new Container(
                      padding: const EdgeInsets.symmetric(
                        vertical: 20.0,
                        horizontal: 20.0,
                      ),
                      child: new Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: <Widget>[
                          new Expanded(
                            child: Text(
                              LOGIN_SCREEN_SIGN_UP,
                              textAlign: TextAlign.center,
                              style: TextStyle(
                                  color: Colors.white,
                                  fontWeight: FontWeight.bold),
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ),
          new Container(
            width: MediaQuery.of(context).size.width,
            margin: const EdgeInsets.only(left: 30.0, right: 30.0, top: 30.0),
            alignment: Alignment.center,
            child: new Row(
              children: <Widget>[
                new Expanded(
                  child: new FlatButton(
                    shape: new RoundedRectangleBorder(
                        borderRadius: new BorderRadius.circular(30.0)),
                    color: Colors.white,
                    onPressed: () => gotoLogin(),
                    child: new Container(
                      padding: const EdgeInsets.symmetric(
                        vertical: 20.0,
                        horizontal: 20.0,
                      ),
                      child: new Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: <Widget>[
                          new Expanded(
                            child: Text(
                              LOGIN_SCREEN_LOGIN,
                              textAlign: TextAlign.center,
                              style: TextStyle(
                                  color: Color.fromRGBO(58, 66, 86, 1.0),
                                  fontWeight: FontWeight.bold),
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  Widget LoginPage() {
    return new Container(
      height: MediaQuery.of(context).size.height,
      decoration: BoxDecoration(
        color: Colors.white,
        image: DecorationImage(
          colorFilter: new ColorFilter.mode(
              Colors.black.withOpacity(0.05), BlendMode.dstATop),
          image: AssetImage('assets/images/drones.jpg'),
          fit: BoxFit.cover,
        ),
      ),
      child: new Column(
        children: <Widget>[
          Container(
            padding: EdgeInsets.all(120.0),
            child: Center(
              child: Icon(
                Icons.school,
                color: Color.fromRGBO(58, 66, 86, 1.0),
                size: 50.0,
              ),
            ),
          ),
          new Row(
            children: <Widget>[
              new Expanded(
                child: new Padding(
                  padding: const EdgeInsets.only(left: 40.0),
                  child: new Text(
                    LOGIN_SCREEN_EMAIL,
                    style: TextStyle(
                      fontWeight: FontWeight.bold,
                      color: Color.fromRGBO(58, 66, 86, 1.0),
                      fontSize: 15.0,
                    ),
                  ),
                ),
              ),
            ],
          ),
          new Container(
            width: MediaQuery.of(context).size.width,
            margin: const EdgeInsets.only(left: 40.0, right: 40.0, top: 10.0),
            alignment: Alignment.center,
            padding: const EdgeInsets.only(left: 0.0, right: 10.0),
            child: new Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisAlignment: MainAxisAlignment.start,
              children: <Widget>[
                new Expanded(
                  child: TextFormField( // LOGIN SCREEN EMAIL
                    maxLines: 1,
                    keyboardType: TextInputType.emailAddress,
                    autofocus: false,
                    textAlign: TextAlign.left,
                    decoration: InputDecoration(
                      icon: Icon(Icons.alternate_email),
                      hintText: LOGIN_SCREEN_EMAIL_HINT,
                      hintStyle: TextStyle(color: Colors.grey),
                    ),
                    validator: (value) => value.isEmpty ? LOGIN_SCREEN_EMAIL_WARNING : null,
                    onSaved: (value) => _email = value,
                  ),
                ),
              ],
            ),
          ),
          Divider(
            height: 24.0,
            color: Color(0x00000000),
          ),
          new Row(
            children: <Widget>[
              new Expanded(
                child: new Padding(
                  padding: const EdgeInsets.only(left: 40.0),
                  child: new Text(
                    LOGIN_SCREEN_PASSWORD,
                    style: TextStyle(
                      fontWeight: FontWeight.bold,
                      color: Color.fromRGBO(58, 66, 86, 1.0),
                      fontSize: 15.0,
                    ),
                  ),
                ),
              ),
            ],
          ),
          new Container(
            width: MediaQuery.of(context).size.width,
            margin: const EdgeInsets.only(left: 40.0, right: 40.0, top: 10.0),
            alignment: Alignment.center,
            padding: const EdgeInsets.only(left: 0.0, right: 10.0),
            child: new Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisAlignment: MainAxisAlignment.start,
              children: <Widget>[
                new Expanded(
                  child: TextFormField( // LOGIN SCREEN PASSWORD
                    obscureText: true,
                    keyboardType: TextInputType.emailAddress,
                    maxLines: 1,
                    autofocus: false,
                    textAlign: TextAlign.left,
                    decoration: InputDecoration(
                      icon: Icon(Icons.lock_outline),
                      hintText: LOGIN_SCREEN_PASSWORD_HINT,
                      hintStyle: TextStyle(color: Colors.grey),
                    ),
                    validator: (value) => value.isEmpty ? LOGIN_SCREEN_PASSWORD_WARNING : null,
                    onSaved: (value) => _password = value,
                  ),
                ),
              ],
            ),
          ),
          Divider(
            height: 24.0,
            color: Color(0x00000000),
          ),
          new Row(
            mainAxisAlignment: MainAxisAlignment.end,
            children: <Widget>[
              Padding(
                padding: const EdgeInsets.only(right: 20.0),
                child: new FlatButton(
                  child: new Text(
                    LOGIN_SCREEN_FORGOT_PASSWORD,
                    style: TextStyle(
                      fontWeight: FontWeight.bold,
                      color: Color.fromRGBO(58, 66, 86, 1.0),
                      fontSize: 15.0,
                    ),
                    textAlign: TextAlign.end,
                  ),
                  onPressed: () => StaticMethods.locked(context),
                ),
              ),
            ],
          ),
          new Container(
            width: MediaQuery.of(context).size.width,
            margin: const EdgeInsets.only(left: 30.0, right: 30.0, top: 20.0),
            alignment: Alignment.center,
            child: new Row(
              children: <Widget>[
                new Expanded(
                  child: new FlatButton( // LOGIN SCREEN LOGIN BUTTON
                    shape: new RoundedRectangleBorder(
                      borderRadius: new BorderRadius.circular(30.0),
                    ),
                    color: Color.fromRGBO(58, 66, 86, 1.0),
                    onPressed: () => _validateAndSubmit(),
                    child: new Container(
                      padding: const EdgeInsets.symmetric(
                        vertical: 20.0,
                        horizontal: 20.0,
                      ),
                      child: new Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: <Widget>[
                          new Expanded(
                            child: Text( 
                              LOGIN_SCREEN_LOGIN,
                              textAlign: TextAlign.center,
                              style: TextStyle(
                                  color: Colors.white,
                                  fontWeight: FontWeight.bold),
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ),
          Divider(
            height: 25.0,
            color: Color(0x00000000),            
          ),
          _showErrorMessage(),
          Divider(
            height: 25.0,
            color: Color(0x00000000),            
          ),
          _showLoading(),
        ],
      ),
    );
  }

  Widget SignupPage() {
    return new Container(
      height: MediaQuery.of(context).size.height,
      decoration: BoxDecoration(
        color: Colors.white,
        image: DecorationImage(
          colorFilter: new ColorFilter.mode(
              Colors.black.withOpacity(0.05), BlendMode.dstATop),
          image: AssetImage('assets/images/drones.jpg'),
          fit: BoxFit.cover,
        ),
      ),
      child: new Column(
        children: <Widget>[
          Container(
            padding: EdgeInsets.all(100.0),
            child: Center(
              child: Icon(
                Icons.school,
                color: Color.fromRGBO(58, 66, 86, 1.0),
                size: 50.0,
              ),
            ),
          ),
          new Row(
            children: <Widget>[
              new Expanded(
                child: new Padding(
                  padding: const EdgeInsets.only(left: 40.0),
                  child: new Text(
                    LOGIN_SCREEN_EMAIL,
                    style: TextStyle(
                      fontWeight: FontWeight.bold,
                      color: Color.fromRGBO(58, 66, 86, 1.0),
                      fontSize: 15.0,
                    ),
                  ),
                ),
              ),
            ],
          ),
          new Container(
            width: MediaQuery.of(context).size.width,
            margin: const EdgeInsets.only(left: 40.0, right: 40.0, top: 10.0),
            alignment: Alignment.center,
            padding: const EdgeInsets.only(left: 0.0, right: 10.0),
            child: new Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisAlignment: MainAxisAlignment.start,
              children: <Widget>[
                new Expanded(
                  child: TextField( //SIGNUP SCREEN EMAIL
                    obscureText: true,
                    textAlign: TextAlign.left,
                    decoration: InputDecoration(
                      hintText: LOGIN_SCREEN_EMAIL_HINT,
                      hintStyle: TextStyle(color: Colors.grey),
                    ),
                  ),
                ),
              ],
            ),
          ),
          Divider(
            height: 24.0,
            color: Color(0x00000000),
          ),
          new Row(
            children: <Widget>[
              new Expanded(
                child: new Padding(
                  padding: const EdgeInsets.only(left: 40.0),
                  child: new Text(
                    LOGIN_SCREEN_PASSWORD,
                    style: TextStyle(
                      fontWeight: FontWeight.bold,
                      color: Color.fromRGBO(58, 66, 86, 1.0),
                      fontSize: 15.0,
                    ),
                  ),
                ),
              ),
            ],
          ),
          new Container(
            width: MediaQuery.of(context).size.width,
            margin: const EdgeInsets.only(left: 40.0, right: 40.0, top: 10.0),
            alignment: Alignment.center,
            padding: const EdgeInsets.only(left: 0.0, right: 10.0),
            child: new Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisAlignment: MainAxisAlignment.start,
              children: <Widget>[
                new Expanded(
                  child: TextField( // SIGNUP SCREEN PASSWORD
                    obscureText: true,
                    textAlign: TextAlign.left,
                    decoration: InputDecoration(
                      hintText: LOGIN_SCREEN_PASSWORD_HINT,
                      hintStyle: TextStyle(color: Colors.grey),
                    ),
                  ),
                ),
              ],
            ),
          ),
          Divider(
            height: 24.0,
            color: Color(0x00000000),
          ),
          new Row(
            children: <Widget>[
              new Expanded(
                child: new Padding(
                  padding: const EdgeInsets.only(left: 40.0),
                  child: new Text( // SIGNUP SCREEN CONFIRM PASSWORD
                    LOGIN_SCREEN_CONFIRM_PASSWORD,
                    style: TextStyle(
                      fontWeight: FontWeight.bold,
                      color: Color.fromRGBO(58, 66, 86, 1.0),
                      fontSize: 15.0,
                    ),
                  ),
                ),
              ),
            ],
          ),
          new Container(
            width: MediaQuery.of(context).size.width,
            margin: const EdgeInsets.only(left: 40.0, right: 40.0, top: 10.0),
            alignment: Alignment.center,
            padding: const EdgeInsets.only(left: 0.0, right: 10.0),
            child: new Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisAlignment: MainAxisAlignment.start,
              children: <Widget>[
                new Expanded(
                  child: TextField(
                    obscureText: true,
                    textAlign: TextAlign.left,
                    decoration: InputDecoration(
                      hintText: LOGIN_SCREEN_PASSWORD_HINT,
                      hintStyle: TextStyle(color: Colors.grey),
                    ),
                  ),
                ),
              ],
            ),
          ),
          Divider(
            height: 24.0,
            color: Color(0x00000000),
          ),
          new Row(
            mainAxisAlignment: MainAxisAlignment.end,
            children: <Widget>[
              Padding(
                padding: const EdgeInsets.only(right: 20.0),
                child: new FlatButton(
                  child: new Text(
                    LOGIN_SCREEN_HAVE_ACCOUNT,
                    style: TextStyle(
                      fontWeight: FontWeight.bold,
                      color: Color.fromRGBO(58, 66, 86, 1.0),
                      fontSize: 15.0,
                    ),
                    textAlign: TextAlign.end,
                  ),
                  onPressed: () => StaticMethods.locked(context),
                ),
              ),
            ],
          ),
          new Container(
            width: MediaQuery.of(context).size.width,
            margin: const EdgeInsets.only(left: 30.0, right: 30.0, top: 50.0),
            alignment: Alignment.center,
            child: new Row(
              children: <Widget>[
                new Expanded(
                  child: new FlatButton( // SIGNUP SCREEN SIGN UP BUTTON
                    shape: new RoundedRectangleBorder(
                      borderRadius: new BorderRadius.circular(30.0),
                    ),
                    color: Color.fromRGBO(58, 66, 86, 1.0),
                    onPressed: () => StaticMethods.locked(context),
                    child: new Container(
                      padding: const EdgeInsets.symmetric(
                        vertical: 20.0,
                        horizontal: 20.0,
                      ),
                      child: new Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: <Widget>[
                          new Expanded(
                            child: Text(
                              LOGIN_SCREEN_SIGN_UP,
                              textAlign: TextAlign.center,
                              style: TextStyle(
                                  color: Colors.white,
                                  fontWeight: FontWeight.bold),
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  PageController _controller = new PageController(initialPage: 1, viewportFraction: 1.0);

  @override
  Widget build(BuildContext context) {
    _isIos = Theme.of(context).platform == TargetPlatform.iOS;
    return Container(
      height: MediaQuery.of(context).size.height,
      width: MediaQuery.of(context).size.width,
      child: new Form (
      key: _formKey,
        child: PageView(
          controller: _controller,
          physics: new AlwaysScrollableScrollPhysics(),
          children: <Widget>[LoginPage(), OptionPage(), SignupPage()],
          scrollDirection: Axis.horizontal,
          onPageChanged: (num){
            switch (num) {
              case 0:
                setState(() {
                  _formKey.currentState.reset();
                  _errorMessage = "";
                  _formMode = FormMode.LOGIN;
                });
                break;
              case 1:
                setState(() {
                  _formKey.currentState.reset();
                  _errorMessage = "";
                  _formMode = FormMode.OPTIONS;
                });
                break;
              case 2:
                setState(() {
                  _formKey.currentState.reset();
                  _errorMessage = "";
                  _formMode = FormMode.SIGNUP;
                });
                break;
            }
          },
        ),        
      ),
    );
  }

Error:

I/flutter (18510): The following assertion was thrown during performLayout():
I/flutter (18510): RenderCustomMultiChildLayoutBox object was given an infinite size during layout.
.....

在错误中,它只显示一个空白页面而不是类(class)页面,检查 firebase 我可以看到用户登录,所以我认为这是一些布局问题。

我尝试过的:

RootPage(我仍然看到一个空白屏幕):

return new LessonPage(
 title: LESSON_PAGE_TITLE,
 userId: _userId,
 auth: widget.auth,
 onSignedOut: _onSignedOut,
);

我试图返回一个普通页面而不是类(class)页面,它只显示一个已经过测试并且有效的加载动画,但我仍然看到一个空白页面:

return _buildWaitingScreen();

LessonPage(仍然看到空白页):

    Widget makeBody(BuildContext context) => Container(
      height: MediaQuery.of(context).size.height / 1.5,
      child: ListView.builder(
        scrollDirection: Axis.vertical,
        shrinkWrap: true,
        itemCount: lessons.length,
        itemBuilder: (BuildContext context, int index) {
          return makeCard(lessons[index]);
        },
      ),
    );    

    return Scaffold(
      backgroundColor: Color.fromRGBO(58, 66, 86, 1.0),
      appBar: topAppBar,
      body: makeBody(context),
      bottomNavigationBar: makeBottom,
    );

最佳答案

下面的代码片段中不需要 ContainerSingleChildScrollView:

      return LessonPage(
        title: LESSON_PAGE_TITLE,
        userId: _userId,
        auth: widget.auth,
        onSignedOut: _onSignedOut,
      );

如果还是不行,

RenderCustomMultiChildLayoutBox object was given an infinite size during layout. 表示您使用了 ListViewScrollView 或任何其他具有无限大小的小部件.为了防止这个问题,请将您的 makeBody ListView 包装成固定大小。如果它正常工作,您可以使用 MediaQuery.of(context).size.height(提供设备屏幕宽度)并调整您想要的大小。

例如:

Widget makeBody(BuildContext context) => Container(
  height: MediaQuery.of(context).size.height / 1.5,
  child: ListView.builder(
    scrollDirection: Axis.vertical,
    shrinkWrap: true,
    itemCount: lessons.length,
    itemBuilder: (BuildContext context, int index) {
      return makeCard(lessons[index]);
    },
  ),
);

并调用方法:body: makeBody(context),

RootPage 中修复:

return new Container(
  height: MediaQuery.of(context).size.height,
  child: LessonPage(
    title: LESSON_PAGE_TITLE,
    userId: _userId,
    auth: widget.auth,
    onSignedOut: _onSignedOut,
  )
);

关于dart - RenderCustomMultiChildLayoutBox 对象在布局错误期间被赋予无限大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56285255/

相关文章:

flutter - 在 Flutter 中失去与设备的连接?

json - 无法在Flutter项目中初始化jsonResponse

layout - Visual Studio Code : Flutter: how to efficiently debug on two simulator at the same time

flutter - 如何使用 Google Maps Plugin Flutter 为另一个类的相机制作动画

flutter - Android Studio Bumblebee 编辑器中未显示 Dart Analysis 问题

flutter - 从函数返回ListView使Flutter Column为空白

http - 加载数据时客户端异常

flutter - 按下时无法更改收藏夹图标颜色

dart - 为什么 FocusNode 需要在 flutter 中配置?

flutter - 如何从 GraphQL 生成 Dart - graphql 到 dart 生成器