flutter - Fultter GridView 滚动
问题描述
我尝试设置物理以启用滚动功能,但它会滚动整个屏幕。
只有红色框可以滚动
如何设置另一个 Widget 是固定位置,只能在 GridView 中启用滚动?
只想在 GridView 中滚动,请参考照片,这样理解更清楚。
child: Scaffold(
appBar: AppBar(
centerTitle: true,
title: Text('Sanfield Mobile App'),
actions: <Widget>[
IconButton(
icon: Icon(
Icons.exit_to_app,
color: Colors.white,
),
onPressed: () {
showConfirmLogoutDialog(context,'Confirm logout','Do you want to logout?');
},
)
],
),
drawer: CustomDrawer(),
body:SingleChildScrollView(
physics: new NeverScrollableScrollPhysics(),
child:Column(
children: <Widget>[
Card(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
ListTile(
leading:
image(),
title: Text(updateDate),
subtitle: Text(weatherDetails),
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
RichText(
text: TextSpan(
style: new TextStyle(
fontSize: 24.0,
color: Colors.black,
),
children: <TextSpan>[
TextSpan(text: mintemp.toString()+' C - ', style: new TextStyle(color: Colors.lightBlue)),
TextSpan(text: maxtemp.toString()+' C ', style: new TextStyle(color: Colors.red)),
TextSpan(text: ' Update:'+updateTime, style: new TextStyle(color: Colors.black,fontSize: 14)),
],
),
),
],
),
],
),
),
Container(
height: 80,
child: new ListView.builder(
itemCount: 6,
itemBuilder: (context, index){
return new Card(child: new Container(
//width: MediaQuery.of(context).size.width,
width:320,
height: 80,
child: new Text('Hello'),alignment: Alignment.center,));
}, scrollDirection: Axis.horizontal,
),
),
Container(
height: 889,
child:GridView.count(
physics: ScrollPhysics(),
primary: false,
padding: const EdgeInsets.all(10),
crossAxisSpacing: 10,
mainAxisSpacing: 10,
crossAxisCount: 3,
children: <Widget>[
Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
'images/hkphoto.jpg'),
fit: BoxFit.fill,
),
shape: BoxShape.circle,
),
child: InkWell(
/*onTap: () => Navigator.push(
context, MaterialPageRoute(builder: (context) =>)
),*/ // handle your onTap here
),
),
InkWell(
child:Container(
padding: const EdgeInsets.all(8),
child: const Text('phs'),
color: Colors.teal[200],
),
/*onTap: () => Navigator.push(
context, MaterialPageRoute(builder: (context) =>
)
),*/
),
InkWell(
child:Container(
padding: const EdgeInsets.all(8),
child: const Text('whs'),
color: Colors.teal[200],
),
/*onTap: () => Navigator.push(
context, MaterialPageRoute(builder: (context) =>
),
),*/
),
InkWell(
child:Container(
padding: const EdgeInsets.all(8),
child: const Text('whs'),
color: Colors.teal[200],
),
/*onTap: () => Navigator.push(
context, MaterialPageRoute(builder: (context) =>
),
),*/
),
InkWell(
child:Container(
padding: const EdgeInsets.all(8),
child: const Text('whs'),
color: Colors.teal[200],
),
/*onTap: () => Navigator.push(
context, MaterialPageRoute(builder: (context) =>
),
),*/
),
InkWell(
child:Container(
padding: const EdgeInsets.all(8),
child: const Text('whs'),
color: Colors.teal[200],
),
/*onTap: () => Navigator.push(
context, MaterialPageRoute(builder: (context) =>
),
),*/
),
],
)
),
]
),
)
)
解决方案
删除SingleChildScrollView
body 顶层的 并将 的设置scrollPhysics
为。GridView
AlwaysScrollableScrollPhysics()
推荐阅读
- flutter - 如何从底部导航触发抽屉?
- java - 如何根据某些特定条件从 Java HashMap 中的值获取密钥?
- reactjs - ReactJS 引导按钮作为链接(新标签)
- html - 表头/行中的tailwindcss隐藏类
- git - yum 在 Centos 上安装旧版本的 git
- c# - 是否从 EntityFrameworkQueryableExtensions 中删除了非异步方法?
- python - 渲染模板时烧瓶无法初始化我的课程
- c# - DataGrid、MVVM 和 IEditableObject
- smtp - G Suite 应用密码 - 只能访问 smtp
- android-studio - 有什么方法可以在 Android 11 中自动接受 BLE 配对请求?