How to use Expanded
in SingleChildScrollView
? I have a screen with Image.network
, ListView.builder
and Row
(
I tried Vijaya Ragavan solution but did some adjustments to it & it still works.
To use Expanded
with SingleChildScrollView
, I used ConstrainedBox
and set its height to the height of the screen (using MediaQuery
). You'll just need to make sure the screen content you put inside ConstrainedBox
is not bigger than the height of the screen.
Otherwise set the height of ConstrainedBox
to height of the content you want to display on the screen.
SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(maxHeight: MediaQuery.of(context).size.height),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Expanded(
child: Text('Hello World!'),
),
],
),
)
)
Edit:
To subtract the height of the AppBar
and/or the Status Bar, see below:
double screenHeightMinusAppBarMinusStatusBar = MediaQuery.of(context).size.height
- appBar.preferredSize.height
- MediaQuery.of(context).padding.top;