Reputation: 9119
I'm building a Chat app flutter page and my Textfield / Send Button Row keeps disappearing and I'm getting the following error...
'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<…>
The page builds fine and displays my information appropriately without the textfield / send row, but errors out when I add it. Here is my code contained in the Scaffold of my Stateful widget...
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)
],
)
],
))
Upvotes: 0
Views: 5089
Reputation: 9119
The answer was to wrap the TextField in a Flexible. Seems obvious now, but sometimes a Flexible or Expanded is needed and sometimes not. Here is my code...
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),
],
),
)
],
)
Upvotes: 7