如何在Flutter中创建对象实例的可迭代集合?

时间:2019-07-02 01:24:30

标签: flutter dart

我创建了一个myObject类型的列表,当我通过list.add添加对象实例,然后传递myObject的构造函数时,我可以引用的第一个属性,后续属性为null

// my class and its constructor method

class Channel {
  final String channelName;
  final String channelDesc;
  final String channelEvent;
  final String channelThumbLink;

  const Channel(this.channelName, this.channelDesc, this.channelEvent,
      this.channelThumbLink);
}

// I construct a list of type<Channel>

final List<Channel> channelList = <Channel>[]
    ..add(Channel(
        'Funkycooking',
        'Welcome to the Funkycooking channel, we cook, you get funky',
        'Sizzling Salsa Saturday!',
        '1'))

// Referencing these elements from the list collection in any widget

Text('${channelList[0].channelName}'),
Text('${channelList[0].channelDesc}'),

Text('${channelList[0].channelName}')按预期返回“ Funkycooking”

Text('${channelList[0].channelDesc}')返回null,我希望“欢迎来到Funkycooking频道,我们做饭,您会变得时髦”

1 个答案:

答案 0 :(得分:0)

抱歉,我错误地认为热重装可以正确反映我的对象编码更改,但不能,但是通过停止并重新启动该应用程序,它的行为符合我的预期。