list.dart 1.74 KB
Newer Older
Adam Barth's avatar
Adam Barth committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/widgets.dart';

import 'constants.dart';
import 'scrollbar_painter.dart';

enum MaterialListType {
  oneLine,
  oneLineWithAvatar,
  twoLine,
  threeLine
}

Hans Muller's avatar
Hans Muller committed
17
Map<MaterialListType, double> kListItemExtent = const <MaterialListType, double>{
Adam Barth's avatar
Adam Barth committed
18 19 20 21 22 23
  MaterialListType.oneLine: kOneLineListItemHeight,
  MaterialListType.oneLineWithAvatar: kOneLineListItemWithAvatarHeight,
  MaterialListType.twoLine: kTwoLineListItemHeight,
  MaterialListType.threeLine: kThreeLineListItemHeight,
};

24
class MaterialList extends StatefulWidget {
Adam Barth's avatar
Adam Barth committed
25 26 27 28
  MaterialList({
    Key key,
    this.initialScrollOffset,
    this.onScroll,
29
    this.type: MaterialListType.twoLine,
30
    this.children,
31
    this.scrollablePadding: EdgeInsets.zero,
32
    this.scrollableKey
Adam Barth's avatar
Adam Barth committed
33 34 35 36 37
  }) : super(key: key);

  final double initialScrollOffset;
  final ScrollListener onScroll;
  final MaterialListType type;
38
  final Iterable<Widget> children;
39
  final EdgeInsets scrollablePadding;
40
  final Key scrollableKey;
Adam Barth's avatar
Adam Barth committed
41

42
  _MaterialListState createState() => new _MaterialListState();
Adam Barth's avatar
Adam Barth committed
43 44
}

45 46
class _MaterialListState extends State<MaterialList> {
  ScrollbarPainter _scrollbarPainter = new ScrollbarPainter();
Adam Barth's avatar
Adam Barth committed
47 48

  Widget build(BuildContext context) {
49
    return new ScrollableList(
50
      key: config.scrollableKey,
Adam Barth's avatar
Adam Barth committed
51
      initialScrollOffset: config.initialScrollOffset,
52
      scrollDirection: Axis.vertical,
Adam Barth's avatar
Adam Barth committed
53
      onScroll: config.onScroll,
Hans Muller's avatar
Hans Muller committed
54
      itemExtent: kListItemExtent[config.type],
55
      padding: const EdgeInsets.symmetric(vertical: 8.0) + config.scrollablePadding,
56 57
      scrollableListPainter: _scrollbarPainter,
      children: config.children
Adam Barth's avatar
Adam Barth committed
58 59 60
    );
  }
}