scrollbar.dart 2.04 KB
Newer Older
1 2 3 4 5 6 7
// 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:intl/intl.dart';
import 'package:flutter/material.dart';

8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
final NumberFormat _dd = new NumberFormat("00", "en_US");

class _Item extends StatelessComponent {
  _Item(this.index);

  int index;

  Widget build(BuildContext context) {
    return new Text('Item ${_dd.format(index)}',
      key: new ValueKey<int>(index),
      style: Theme.of(context).text.title
    );
  }
}

23 24 25 26 27 28 29 30 31 32
class ScrollbarApp extends StatefulComponent {
  ScrollbarAppState createState() => new ScrollbarAppState();
}

class ScrollbarAppState extends State<ScrollbarApp> {
  final int _itemCount = 20;
  final double _itemExtent = 50.0;
  final ScrollbarPainter _scrollbarPainter = new ScrollbarPainter();

  Widget _buildMenu(BuildContext context) {
33
    return new ScrollableList(
34
      itemExtent: _itemExtent,
35 36
      scrollableListPainter: _scrollbarPainter,
      children: new List<Widget>.generate(_itemCount, (int i) => new _Item(i))
37 38 39 40 41 42 43
    );
  }

  Widget build(BuildContext context) {
    Widget scrollable = new Container(
      margin: new EdgeDims.symmetric(horizontal: 6.0), // TODO(hansmuller) 6.0 should be based on _kScrollbarThumbWidth
      child: new Center(
44 45
        widthFactor: 1.0,
        heightFactor: 1.0,
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
        child: new Container(
          width: 80.0,
          height: _itemExtent * 5.0,
          child: _buildMenu(context)
        )
      )
    );

    return new Scaffold(
      toolBar: new ToolBar(center: new Text('Scrollbar Demo')),
      body: new Container(
        padding: new EdgeDims.all(12.0),
        child: new Center(child: new Card(child: scrollable))
      )
    );
  }
}

void main() {
  runApp(new MaterialApp(
    title: 'ScrollbarApp',
    theme: new ThemeData(
      brightness: ThemeBrightness.light,
      primarySwatch: Colors.blue,
      accentColor: Colors.redAccent[200]
    ),
Hixie's avatar
Hixie committed
72
    routes: <String, RouteBuilder>{
Adam Barth's avatar
Adam Barth committed
73
      '/': (RouteArguments args) => new ScrollbarApp(),
74 75 76
    }
  ));
}