如何使用Pageable懒惰列表

时间:2016-12-08 04:11:52

标签: dart flutter

我想创建一个很长的小部件列表,用户可能想要滚动浏览,就像一本书。 我注意到了PageableLazyList类,但我不太明白应该如何使用它。

class NotePage extends PageableLazyList {

  NotePage({Key key, this.note}) : super(key: key,itemBuilder: itembuilder); 
  final Note note;

  static List<NoteContainer> itembuilder (BuildContext context, num start, num count ){
    List<NoteContainer> result = <NoteContainer>[];
    for(num i = start; i < start+count; i++){
      result.add(new NoteContainer(new Note(title: "Note " + i.toString(), description:  "Description " + i.toString())));
    }
    return result;
  }


}

没有用!我在这里需要一个构建方法,但无法理解我应该做什么。

1 个答案:

答案 0 :(得分:2)

这实际上有效:

class NotePageList extends PageableLazyList {

  NotePageList({Key key}) : super(key: key,
      scrollDirection: Axis.horizontal,
      itemCount : 10000,
      itemBuilder: itembuilder){
  }

  static List<NoteContainer> itembuilder (BuildContext context, num start, num count ){
    List<NoteContainer> result = <NoteContainer>[];
    for(num i = start; i < start+count; i++){
      result.add(new NoteContainer(new Note(title: "Note " + i.toString(), description:  "Description " + i.toString())));
    }
    return result;
  }


}