Reputation: 4519
I am trying to populate some data in a row. But whenever I run the following code it gives error.
Code
Scaffold(
body: SafeArea(
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Row(
mainAxisSize: MainAxisSize.max,
children: [
ListView.builder(
shrinkWrap: true,
itemCount: rideInfo[0]['matched'][0]['companionInfo'].length,
itemBuilder: (context, index) {
return Container(
color: Colors.red,
height: 40,
width: 40,
child: Text("Test"),
);
},
),
],
),
),
),
)
Error
The following assertion was thrown during performLayout():
'package:flutter/src/rendering/viewport.dart': Failed assertion: line 1890 pos 16: 'constraints.hasBoundedWidth': is not true.
package:flutter/…/rendering/viewport.dart:1890
2
Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
https://github.com/flutter/flutter/issues/new?template=2_bug.md
The relevant error-causing widget was
ListView
However if I change Row to Column, it seems to be working fine. How can I fix the error?
Upvotes: 2
Views: 96
Reputation: 1394
You can not two infinite scroll widget in the same widget tree. You are using SingleChildScrollView
and Listview
both in the same widget tree. You have change this like:
Scaffold(
body: SafeArea(
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Row(
mainAxisSize: MainAxisSize.max,
children: [
SizedBox(
height: 50,
child:ListView.builder(
scrollDirection:Axis.horizontal,
shrinkWrap: true,
itemCount: rideInfo[0]['matched'][0]['companionInfo'].length,
itemBuilder: (context, index) {
return Container(
color: Colors.red,
height: 40,
width: 40,
child: Text("Test"),
);
},
),
)
],
),
),
),
)
Upvotes: 3