slider_demo.dart 1.84 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
// 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/material.dart';

class SliderDemo extends StatefulComponent {
  _SliderDemoState createState() => new _SliderDemoState();
}

class _SliderDemoState extends State<SliderDemo> {
Hixie's avatar
Hixie committed
12
  double _value = 25.0;
13 14

  Widget build(BuildContext context) {
15 16
    return new Scaffold(
      toolBar: new ToolBar(center: new Text("Sliders")),
17
      body: new Block(children: <Widget>[
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
        new Container(
          height: 100.0,
          child: new Center(
            child:  new Row(
              children: <Widget>[
                new Slider(
                  value: _value,
                  min: 0.0,
                  max: 100.0,
                  onChanged: (double value) {
                    setState(() {
                      _value = value;
                    });
                  }
                ),
                new Container(
                  padding: const EdgeDims.symmetric(horizontal: 16.0),
                  child: new Text(_value.round().toString().padLeft(3, '0'))
                ),
              ],
              justifyContent: FlexJustifyContent.collapse
            )
40
          )
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
        ),
        new Container(
          height: 100.0,
          child: new Center(
            child:  new Row(
              children: <Widget>[
                // Disabled, but tracking the slider above.
                new Slider(value: _value / 100.0),
                new Container(
                  padding: const EdgeDims.symmetric(horizontal: 16.0),
                  child: new Text((_value / 100.0).toStringAsFixed(2))
                ),
              ],
              justifyContent: FlexJustifyContent.collapse
            )
56
          )
57
        )
58 59
      ])
    );
60 61
  }
}