The issue I couldn't solve was having a ListView widget with more items than there was space on the page. This is no problem until you try to build this into some kind of layout, where you have to give a container a size. I want the page to be responsive so setting a fixed size is not an opption.
The solution was to find the size of the viewport using MediaQuery and using the result to set the height of a Container widget.
Here's my code:
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
//Header Container
Container(
height: 80.0,
padding: const EdgeInsets.all(8.0),
color: Colors.blue,
alignment: Alignment.center,
child:
TextField(
decoration: InputDecoration(hintText: "Enter Text Here"),
),
),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
//Body Container
Expanded(
flex: 2,
child: SingleChildScrollView(
padding: const EdgeInsets.all(10.0),
child: Column(
children: <Widget>[
Container(
height: MediaQuery.of(context).size.height-100.0,
alignment: Alignment.center,
child: ListView.builder(
itemBuilder: (context, index){
return Card(
child: Padding(
padding: const EdgeInsets.all(5.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(_students[index].firstName + ' ' + _students[index].lastName),
],
),
),
);
},
itemCount: _students.length,
),
),
],
),
),
),
Expanded(
flex: 3,
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Container(
color: Colors.green,
alignment: Alignment.topLeft,
child: Text('Right')
),
),
),
],
),
],
),
),
);
}
}