material_list.dart 1.55 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 StatefulComponent {
Adam Barth's avatar
Adam Barth committed
25 26 27 28
  MaterialList({
    Key key,
    this.initialScrollOffset,
    this.onScroll,
29 30
    this.type: MaterialListType.twoLine,
    this.children
Adam Barth's avatar
Adam Barth committed
31 32 33 34 35
  }) : super(key: key);

  final double initialScrollOffset;
  final ScrollListener onScroll;
  final MaterialListType type;
36
  final Iterable<Widget> children;
Adam Barth's avatar
Adam Barth committed
37

38
  _MaterialListState createState() => new _MaterialListState();
Adam Barth's avatar
Adam Barth committed
39 40
}

41 42
class _MaterialListState extends State<MaterialList> {
  ScrollbarPainter _scrollbarPainter = new ScrollbarPainter();
Adam Barth's avatar
Adam Barth committed
43 44

  Widget build(BuildContext context) {
45
    return new ScrollableList(
Adam Barth's avatar
Adam Barth committed
46
      initialScrollOffset: config.initialScrollOffset,
47
      scrollDirection: Axis.vertical,
Adam Barth's avatar
Adam Barth committed
48
      onScroll: config.onScroll,
Hans Muller's avatar
Hans Muller committed
49
      itemExtent: kListItemExtent[config.type],
Adam Barth's avatar
Adam Barth committed
50
      padding: const EdgeDims.symmetric(vertical: 8.0),
51 52
      scrollableListPainter: _scrollbarPainter,
      children: config.children
Adam Barth's avatar
Adam Barth committed
53 54 55
    );
  }
}