gpt4 book ai didi

android - Flutter:如何禁用 GridView 小部件的滚动,但为整个页面启用滚动?

转载 作者:行者123 更新时间:2023-12-04 23:54:45 29 4
gpt4 key购买 nike

我正在构建一个应用程序,其中有一个页面,该页面提供有关特定交易卡的信息。我希望页面是可滚动的,但我也希望在页面上有一个网格,每个网格单元格显示一个数据点。我使用 GridView.count() 制作了网格。
我的问题是,我没有可以滚动浏览的页面,而是页面的上半部分保持静态,而网格是可滚动的。如何使网格静态,而页面的其余部分可滚动?我还打算在此网格下方有更多数据,并且我希望用户能够滚动查看所有数据,网格是页面的静态组件。
这是我的代码:

import 'package:flutter/material.dart';
import 'package:pokehub/size_config.dart';
import 'package:pokemon_tcg/pokemon_tcg.dart';

class CardInfo extends StatefulWidget {
PokemonCard card;

CardInfo({required this.card});

@override
_CardInfoState createState() => _CardInfoState();
}

class _CardInfoState extends State<CardInfo> {
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
backgroundColor: Colors.grey[900],
appBar: AppBar(
title: Text(
"Card Profile",
style: TextStyle(
color: Colors.white,
fontFamily: 'Blinker',
fontSize: SizeConfig.blockSizeVertical * 3),
),
backgroundColor: Colors.red,
elevation: 0.0,
),
body: Align(
alignment: Alignment.center,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
height: SizeConfig.blockSizeVertical * 3,
),
Text(
"Set: " +
widget.card.set.name +
" // Number: " +
widget.card.number,
style: TextStyle(
color: Colors.white,
fontFamily: 'Blinker',
fontSize: SizeConfig.blockSizeVertical * 2),
),
SizedBox(
height: SizeConfig.blockSizeVertical * 3,
),
Hero(
tag: 'card' + widget.card.id,
child: Image.network(
widget.card.images.large,
height: SizeConfig.blockSizeVertical * 30,
),
),
SizedBox(
height: SizeConfig.blockSizeVertical * 2,
),
Text(
widget.card.name,
style: TextStyle(
color: Colors.white,
fontFamily: 'Blinker',
fontSize: SizeConfig.blockSizeVertical * 5,
),
),
SizedBox(
height: SizeConfig.blockSizeVertical * 2,
),
Expanded(
child: GridView.count(
mainAxisSpacing: SizeConfig.blockSizeVertical * 4,
crossAxisSpacing: SizeConfig.blockSizeHorizontal * 4,
crossAxisCount: 3,
children: [
Container(
padding: EdgeInsets.symmetric(
vertical: SizeConfig.blockSizeVertical * 2,
horizontal: SizeConfig.blockSizeHorizontal * 2),
decoration: BoxDecoration(
border: Border.all(
color: Colors.white,
),
borderRadius: BorderRadius.all(Radius.circular(20)),
),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Subtypes",
style: TextStyle(
color: Colors.white,
fontFamily: 'Blinker',
fontSize: SizeConfig.blockSizeVertical * 3,
fontWeight: FontWeight.bold),
),
Text(
widget.card.subtypes
.map((e) => e.type)
.join(", "),
style: TextStyle(
color: Colors.white,
fontFamily: 'Blinker',
fontSize: SizeConfig.blockSizeVertical * 2,
),
)
],
),
),
),
Container(
padding: EdgeInsets.symmetric(
vertical: SizeConfig.blockSizeVertical * 2,
horizontal: SizeConfig.blockSizeHorizontal * 2),
decoration: BoxDecoration(
border: Border.all(
color: Colors.white,
),
borderRadius: BorderRadius.all(Radius.circular(20)),
),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"HP",
style: TextStyle(
color: Colors.white,
fontFamily: 'Blinker',
fontSize: SizeConfig.blockSizeVertical * 3,
fontWeight: FontWeight.bold),
),
Text(
widget.card.hp!,
style: TextStyle(
color: Colors.white,
fontFamily: 'Blinker',
fontSize: SizeConfig.blockSizeVertical * 2,
),
)
],
),
),
),
Container(
padding: EdgeInsets.symmetric(
vertical: SizeConfig.blockSizeVertical * 2,
horizontal: SizeConfig.blockSizeHorizontal * 2),
decoration: BoxDecoration(
border: Border.all(
color: Colors.white,
),
borderRadius: BorderRadius.all(Radius.circular(20)),
),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Type",
style: TextStyle(
color: Colors.white,
fontFamily: 'Blinker',
fontSize: SizeConfig.blockSizeVertical * 3,
fontWeight: FontWeight.bold),
),
Text(
widget.card.types.map((e) => e.type).join(", "),
style: TextStyle(
color: Colors.white,
fontFamily: 'Blinker',
fontSize: SizeConfig.blockSizeVertical * 2,
),
)
],
),
),
),
Container(
padding: EdgeInsets.symmetric(
vertical: SizeConfig.blockSizeVertical * 2,
horizontal: SizeConfig.blockSizeHorizontal * 2),
decoration: BoxDecoration(
border: Border.all(
color: Colors.white,
),
borderRadius: BorderRadius.all(Radius.circular(20)),
),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Weakness",
style: TextStyle(
color: Colors.white,
fontFamily: 'Blinker',
fontSize: SizeConfig.blockSizeVertical * 3,
fontWeight: FontWeight.bold),
),
Text(
widget.card.weaknesses
.map((e) => e.type + e.value)
.join(", "),
style: TextStyle(
color: Colors.white,
fontFamily: 'Blinker',
fontSize: SizeConfig.blockSizeVertical * 2,
),
)
],
),
),
),
Container(
padding: EdgeInsets.symmetric(
vertical: SizeConfig.blockSizeVertical * 2,
horizontal: SizeConfig.blockSizeHorizontal * 2),
decoration: BoxDecoration(
border: Border.all(
color: Colors.white,
),
borderRadius: BorderRadius.all(Radius.circular(20)),
),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Resistance",
style: TextStyle(
color: Colors.white,
fontFamily: 'Blinker',
fontSize: SizeConfig.blockSizeVertical * 3,
fontWeight: FontWeight.bold),
),
Text(
widget.card.resistances
.map((e) =>
e.type == "" ? "None" : e.type + e.value)
.join(", "),
style: TextStyle(
color: Colors.white,
fontFamily: 'Blinker',
fontSize: SizeConfig.blockSizeVertical * 2,
),
)
],
),
),
),
Container(
padding: EdgeInsets.symmetric(
vertical: SizeConfig.blockSizeVertical * 2,
horizontal: SizeConfig.blockSizeHorizontal * 2),
decoration: BoxDecoration(
border: Border.all(
color: Colors.white,
),
borderRadius: BorderRadius.all(Radius.circular(20)),
),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Retreat Cost",
style: TextStyle(
color: Colors.white,
fontFamily: 'Blinker',
fontSize: SizeConfig.blockSizeVertical * 3,
fontWeight: FontWeight.bold),
),
Text(
widget.card.convertedRetreatCost.toString(),
style: TextStyle(
color: Colors.white,
fontFamily: 'Blinker',
fontSize: SizeConfig.blockSizeVertical * 2,
),
)
],
),
),
),
],
),
),
],
),
),
),
);
}
}
[enter image description here][1]

最佳答案

您可以提供 physics: NeverScrollableScrollPhysics() GridView禁用滚动效果。如果您希望可滚 Action 为辅助小部件,请使用 primary: false,要使整页滚动,您可以使用 body:SingleChildScrollView(..) 或更好地使用 body:CustomScrollView(..)

关于android - Flutter:如何禁用 GridView 小部件的滚动,但为整个页面启用滚动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71005867/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com