gpt4 book ai didi

widget - Flutter Row 在构建时消失了吗?

转载 作者:IT王子 更新时间:2023-10-29 07:10:11 25 4
gpt4 key购买 nike

我正在构建一个聊天应用程序 flutter 页面,我的文本字段/发送按钮行不断消失,我收到以下错误...

'package:flutter/src/rendering/box.dart': Failed assertion: line 1446 pos 12: 'hasSize': RenderBox was not laid out: 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 (package: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/rendering/p<…>

页面构建良好并在没有文本字段/发送行的情况下适本地显示我的信息,但是当我添加它时出错。这是我的有状态小部件的脚手架中包含的代码...

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

],
))

最佳答案

答案是将 TextField 包装在 Flexible 中。现在看起来很明显,但有时需要 Flexible 或 Expanded,有时则不需要。这是我的代码...

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

关于widget - Flutter Row 在构建时消失了吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50690610/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com