我正在尝试在我的应用程序中构建一个 2x3 GridView,它在大屏幕设备上运行良好,但对于 iPhone SE(4 英寸)这样的设备,GridView 无法自行缩放。它以滚动或从底部溢出的形式出现。
我如何确保所有其他小部件都放置在它们的位置,其余空间由 GridView 使用,并且没有滚动,每个项目都是可见的?您可以查看下面的代码,也可以查看此代码笔
import 'package:flutter/material.dart';
class StatsScreen extends StatefulWidget {
static const String id = 'stats_screen';
StatsScreen({Key key}) : super(key: key);
@override
_StatsScreenState createState() => _StatsScreenState();
}
class _StatsScreenState extends State<StatsScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
padding:
EdgeInsets.only(top: 60.0, left: 20.0, right: 20.0, bottom: 0.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Text(
'MyText',
style: TextStyle(fontSize: 30.0, fontWeight: FontWeight.w700),
),
SizedBox(
height: 20,
),
Expanded(
child: GridView.count(
primary: false,
shrinkWrap: true,
padding: const EdgeInsets.all(0),
crossAxisSpacing: 10,
mainAxisSpacing: 10,
crossAxisCount: 2,
children: <Widget>[
Container(
padding: const EdgeInsets.all(8),
child: const Text('He\'d have you all unravel at the'),
color: Colors.teal[100],
),
Container(
padding: const EdgeInsets.all(8),
child: const Text('Heed not the rabble'),
color: Colors.teal[200],
),
Container(
padding: const EdgeInsets.all(8),
child: const Text('Sound of screams but the'),
color: Colors.teal[300],
),
Container(
padding: const EdgeInsets.all(8),
child: const Text('Who scream'),
color: Colors.teal[400],
),
Container(
padding: const EdgeInsets.all(8),
child: const Text('Revolution is coming...'),
color: Colors.teal[500],
),
Container(
padding: const EdgeInsets.all(8),
child: const Text('Revolution, they...'),
color: Colors.teal[600],
),
],
),
),
SizedBox(
height: 30.0,
),
RaisedButton(
onPressed: () {},
child: Text(
'MyRaisedButton',
style: TextStyle(
fontSize: 30.0,
color: Colors.white,
),
),
color: Colors.red[900],
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
),
)
],
),
),
);
}
}