SizedBox.expand
results in the DataTable
taking an infinite height which the SingleChildScrollView
won’t like. Since you only want to span the width of the parent, you can use a LayoutBuilder
to get the size of the parent you care about and then wrap the DataTable
in a ConstrainedBox
.
Widget build(BuildContext context) {
return Scaffold(
body: LayoutBuilder(
builder: (context, constraints) => SingleChildScrollView(
child: Column(
children: [
const Text('My Text'),
Container(
alignment: Alignment.topLeft,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: ConstrainedBox(
constraints: BoxConstraints(minWidth: constraints.minWidth),
child: DataTable(columns: [], rows: []),
),
),
),
],
),
),
),
);
}