给GridView再嵌套一层Expanded就OK,如以下代码:
class GridViewRoute extends StatelessWidget {
const GridViewRoute({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: "GridViewRoute",
home: Scaffold(
appBar: AppBar(
title: const Text("GridViewRoute"),
),
body: Center(
child: Column(
children: [
Expanded(
child: GridView(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
childAspectRatio: 1
),
children: const [
Icon(Icons.ac_unit),
Icon(Icons.airport_shuttle),
Icon(Icons.all_inclusive),
Icon(Icons.beach_access),
Icon(Icons.cake),