2017-04-24 80 views
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; 
} 

然后,在类TravelDestinationItembuild功能:

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...

我对这种行为很困惑。

谁能帮助?

回答

2

由于您使用不同高度的物品,你应该从通话中删除此行的ListView构造:

itemExtent: TravelDestinationItem.height, 

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

+0

谢谢!稍后注意到这一点。 – TaylorR