首页 文章

Flutter Row在构建时消失了吗?

提问于
浏览
0

我正在构建一个Chat app flutter页面,我的Textfield / Send Button Row一直在消失,我收到以下错误...

'package:flutter / src / rendering / box.dart':断言失败:第1446行pos:'hasSize':RenderBox未布局:RenderPointerListener#da9fd NEEDS-LAYOUT NEEDS-PAINT 0 _AssertionError._doThrowNew(dart:core -patch / dart:core / errors_patch.dart:37)1 _AssertionError._throwNew(dart:core-patch / dart:core / errors_patch.dart:33)2 RenderBox.size(package:flutter / src / rendering / box.dart :1446:12)3 RenderProxyBoxWithHitTestBehavior.hitTest(包:flutter / src / rendering / proxy_box.dart:164:9)4 RenderBox&ContainerRenderObjectMixin&RenderBoxContainerDefaultsMixin.defaultHitTestChildren(package:flutter / src / rendering / box.dart:2190:17)5 RenderCustomMultiChildLayoutBox . hitTestChildren(package:flutter / src / rendering / custom_layout.dart:365:12)6 RenderBox.hitTest(package:flutter / src / rendering / box.dart:1863:11)7 RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.hitTestChildren(package:flutter / src /渲染/ p <...>

页面构建正常并在没有textfield / send行的情况下正确显示我的信息,但在添加时出错 . 这是我的有状态小部件的脚手架中包含的代码...

body: new Container(
          margin: new EdgeInsets.all(10.0),
          child: new Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              new Flexible(
                  child: new FirebaseAnimatedList(
                      query: fb.child('users').limitToLast(50),
                      padding: new EdgeInsets.all(5.0),
                      reverse: true,
                      itemBuilder: (_, DataSnapshot snapshot, Animation<double> animation, int index){

                        return new ChatMessage(
                            snapshot: snapshot,
                            animation: animation
                        );

                      })
              ),
              new Divider(height: 16.0, color: Colors.blue,),
              new Padding(padding: new EdgeInsets.all(10.0)),
              new Row(
                mainAxisAlignment: MainAxisAlignment.center,
                mainAxisSize: MainAxisSize.max,
                children: <Widget>[
                  new IconButton(icon: new Icon(Icons.gif), onPressed: null),
                  new Padding(padding: new EdgeInsets.all(3.0)),
                  new TextField(
                      decoration:
                      new InputDecoration(labelText: "CHAT HERE!!"),
                      controller: _searchController,
                      onSubmitted: (str) {
                        setState(() {
                          str = _searchController.text;
                        });
                      }),
                  new IconButton(icon: new Icon(Icons.send), onPressed: null)
                ],
              )

            ],
          ))

1 回答

  • 1

    答案是将TextField包装在Flexible中 . 现在似乎很明显,但有时需要灵活或扩展,有时不需要 . 这是我的代码......

    child: new Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  new Flexible(
                    child: new FirebaseAnimatedList(
                        query: fb.child('users').limitToLast(50),
                        padding: new EdgeInsets.all(5.0),
                        reverse: true,
                        itemBuilder: (_, DataSnapshot snapshot,
                            Animation<double> animation, int index) {
                          return new ChatMessage(
                              snapshot: snapshot, animation: animation);
                        }),
                  ),
                  new Divider(
                    height: 5.0,
                    color: Colors.blue,
                  ),
                  new Container(
                    margin: const EdgeInsets.symmetric(horizontal: 2.0),
                    child: new Row(
                      children: <Widget>[
                        new IconButton(
                            icon: new Icon(Icons.gif), onPressed: getGif),
                        new Flexible(
                          child: new TextField(
                            controller: _chatController,
                            autocorrect: false,
                            decoration: new InputDecoration(
                                labelText: "Let's Talk ... ",
                                labelStyle:
                                    new TextStyle(fontWeight: FontWeight.bold)),
                            onChanged: (str) {
                              setState(() {
                                str = _chatController.text;
                              });
                            },
                          ),
                        ),
                        new IconButton(
                            icon: new Icon(Icons.send), onPressed: getGif),
                      ],
                    ),
                  )
                ],
              )
    

相关问题