0
我試圖修改在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...
我對這種行爲很困惑。
誰能幫助?
謝謝!稍後注意到這一點。 – TaylorR