Reputation: 847
Why i have this error whereas all variables is iniatialize.
════════ Exception caught by rendering library ═════════════════════════════════ RenderBox was not laid out: _RenderLayoutBuilder#657cb relayoutBoundary=up1 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE 'package:flutter/src/rendering/box.dart': Failed assertion: line 1681 pos 12: 'hasSize' User-created ancestor of the error-causing widget was Scaffold ════════ Exception caught by rendering library ═════════════════════════════════ The method '>' was called on null. Receiver: null Tried calling: >(1e-10) User-created ancestor of the error-causing widget was OrientationBuilder lib\no_events.dart:31 ═══════════════════════
class _NoEvents extends State<NoEvents> {
List<Contributor> contributors = [];
List<Event> events = [];
Contributor contributor = new Contributor(1, "XXX");
@override
Widget build(BuildContext context) {
contributors.add(contributor);
Event event1 = new Event(1, contributors, DateTime(2019 - 10 - 25), "XXX", "Test1");
Event event2 = new Event(1, contributors, DateTime.now(), "XXX", "Test2");
Event event3 = new Event(1, contributors, DateTime.now(), "XXX", "Test3");
events.add(event1);
events.add(event2);
events.add(event3);
return Scaffold(
appBar: AppBar(
title: new Text('Lille Events'),
),
body: new OrientationBuilder(
builder: (context, orientation) {
return new Column(
children: <Widget>[
new GridView.count(
crossAxisCount: orientation == Orientation.portrait ? 2 : 3,
children: <Widget>[
for (var e in events)
new Center(
child: new Text(e.subject),
),
],
),
],
);
},
),
);
}
}
Upvotes: 2
Views: 6783
Reputation: 17824
I ran into this error when trying to place a PageView widget inside a Column. The fix was to wrap the PageView widget in a Flexible() widget.
By default the PageView widget doesn't have a fixed size since it depends on the size of its children. Wrapping it in Flexible() solves any overflow issues you might encounter.
Upvotes: -1
Reputation: 29468
GridView
inside Column
causes this error. Try to wrap it in Expanded
class _NoEvents extends State<NoEvents> {
List<Contributor> contributors = [];
List<Event> events = [];
Contributor contributor = new Contributor(1, "XXX");
@override
Widget build(BuildContext context) {
contributors.add(contributor);
Event event1 =
new Event(1, contributors, DateTime(2019 - 10 - 25), "XXX", "Test1");
Event event2 = new Event(1, contributors, DateTime.now(), "XXX", "Test2");
Event event3 = new Event(1, contributors, DateTime.now(), "XXX", "Test3");
events.add(event1);
events.add(event2);
events.add(event3);
return Scaffold(
appBar: AppBar(
title: Text('Lille Events'),
),
body: OrientationBuilder(
builder: (context, orientation) {
return Column(
children: <Widget>[
Expanded(
child: GridView.count(
crossAxisCount: orientation == Orientation.portrait ? 2 : 3,
children: <Widget>[
for (var e in events)
Center(
child: Text(e.subject),
),
],
),
)
],
);
},
),
);
}
}
Upvotes: 9