Fultter GridView scrolling



我试图设置物理来启用滚动功能,但它会滚动整个屏幕
只有红色框可滚动
我如何设置到另一个小工具是固定位置,只在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,如下所示:

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,并将GridViewscrollPhysics设置为AlwaysScrollableScrollPhysics()

最新更新