Reputation: 115
I am new to flutter. I am trying to build a card app and I have a ListView for the suites of each card. I just realized that when I flip the screen to landscape mode, I get a overflow error. I figured it would be fine because I have a ListView. But nope. So I flipped it back to portrait and added some HUGE text to see if that would scroll and to my suprise it did not.
I did some research and added physics: const AlwaysScrollableScrollPhysics(),
but still not working. All help is appreciated!
ListView(
scrollDirection: Axis.vertical,
physics: const AlwaysScrollableScrollPhysics(),
shrinkWrap: true,
children: [
for (var item in suites)
Text('test', style: TextStyle(fontSize: 100.0),),
for (var item in suites)
FlatButton(
onPressed: () {
var suiteId = item.suiteId;
var suite = item.suite;
var suiteImage = item.suiteImage;
var suiteColor = item.suiteColor;
print(suiteColor);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SuiteScreen(
suiteId: suiteId,
suite: suite,
suiteImage: suiteImage,
suiteColor: suiteColor,
),
),
);
},
child: ListTile(
leading: Icon(Icons.deck),
title: Text(
item.suite,
style: TextStyle(
fontSize: 30.0,
),
),
),
),
],
);
Upvotes: 0
Views: 123
Reputation: 597
just wrap your listview with the SingleChildScrollView widget and it'll work fine after that. You can copy paste the below code.
SingleChildScrollView(
child: ListView(
scrollDirection: Axis.vertical,
physics: const AlwaysScrollableScrollPhysics(),
shrinkWrap: true,
children: [
for (var item in suites)
Text('test', style: TextStyle(fontSize: 100.0),),
for (var item in suites)
FlatButton(
onPressed: () {
var suiteId = item.suiteId;
var suite = item.suite;
var suiteImage = item.suiteImage;
var suiteColor = item.suiteColor;
print(suiteColor);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SuiteScreen(
suiteId: suiteId,
suite: suite,
suiteImage: suiteImage,
suiteColor: suiteColor,
),
),
);
},
child: ListTile(
leading: Icon(Icons.deck),
title: Text(
item.suite,
style: TextStyle(
fontSize: 30.0,
),
),
),
),
],
)
);
Upvotes: 1
Reputation:
Try this code
You can implement scrollable row in flutter using the below code
and for scrollable column just change Column with Row
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: <Widget>[
Text('hi'),
Text('hi'),
Text('hi'),
]
)
)
Upvotes: 0
Reputation: 115
The answer was sooooo simple! Just wrap my container which was calling the listview with a Expanded widget!
Upvotes: 0