gpt4 book ai didi

Flutter 画廊演示 : Cards to change card's height

转载 作者:IT王子 更新时间:2023-10-29 07:14:53 26 4
gpt4 key购买 nike

我正在尝试修改 Flutter 示例中的 cards_demo.dart。我的目的是不是将内置的两张卡片的高度固定为:

static final double height=300.0(或一些强制和固定的数字),我希望两张卡具有不同的高度。

所以我修改了 TravelDestination 类以包含属性 height:

class TravelDestination {
const TravelDestination({ this.assetName, this.title, this.description, this.height });

final String assetName;
final String title;
final List<String> description;
final double height;

bool get isValid => assetName != null && title != null && description?.length == 3;
}

然后,在类 TravelDestinationItem build 函数中:

class TravelDestinationItem extends StatelessWidget {
TravelDestinationItem({ Key key, @required this.destination }) : super(key: key) {
assert(destination != null && destination.isValid);
}

static final double height = 512.0;
final TravelDestination destination;

@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context);
final TextStyle titleStyle = theme.textTheme.headline.copyWith(color: Colors.white);
final TextStyle descriptionStyle = theme.textTheme.subhead;

return new Container(
padding: const EdgeInsets.all(8.0),
height: destination.height,
//height: height,
child: new Card(
child: new Column(... ...

我为两张卡片分配了不同的 height 属性,但结果不起作用:它们仍然与 static final double height 指定的高度相同。

如果我注释掉 static final double height 行,编译器会提醒我:No static getter 'height' declared...

我对这种行为感到非常困惑。

有人能帮忙吗?

最佳答案

由于您使用的是不同高度的项目,因此您应该从对 ListView 构造函数的调用中删除这一行:

itemExtent: TravelDestinationItem.height,

此外,您需要热重启应用(热重载不会使用新数据更新目的地列表,因为它是一个全局变量)。

关于Flutter 画廊演示 : Cards to change card's height,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43585588/

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