slider_demo.dart 2.21 KB
Newer Older
1 2 3 4 5 6
// 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';

7
class SliderDemo extends StatefulWidget {
8
  static const String routeName = '/material/slider';
9

10
  @override
11 12 13 14
  _SliderDemoState createState() => new _SliderDemoState();
}

class _SliderDemoState extends State<SliderDemo> {
Hixie's avatar
Hixie committed
15
  double _value = 25.0;
16
  double _discreteValue = 20.0;
17

18
  @override
19
  Widget build(BuildContext context) {
20
    return new Scaffold(
21
      appBar: new AppBar(title: const Text('Sliders')),
22 23
      body: new Padding(
        padding: const EdgeInsets.symmetric(horizontal: 40.0),
24 25 26 27 28 29 30 31 32 33
        child: new Column(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: <Widget>[
            new Column(
              mainAxisSize: MainAxisSize.min,
              children: <Widget> [
                new Slider(
                  value: _value,
                  min: 0.0,
                  max: 100.0,
34
                  thumbOpenAtMin: true,
35 36 37 38 39 40
                  onChanged: (double value) {
                    setState(() {
                      _value = value;
                    });
                  }
                ),
41
                const Text('Continuous'),
42 43 44 45 46
              ]
            ),
            new Column(
              mainAxisSize: MainAxisSize.min,
              children: <Widget> [
47
                const Slider(value: 0.25, thumbOpenAtMin: true, onChanged: null),
48
                const Text('Disabled'),
49 50 51 52 53 54 55 56 57 58 59
              ]
            ),
            new Column(
              mainAxisSize: MainAxisSize.min,
              children: <Widget> [
                new Slider(
                  value: _discreteValue,
                  min: 0.0,
                  max: 100.0,
                  divisions: 5,
                  label: '${_discreteValue.round()}',
60
                  thumbOpenAtMin: true,
61 62 63 64 65 66
                  onChanged: (double value) {
                    setState(() {
                      _discreteValue = value;
                    });
                  }
                ),
67
                const Text('Discrete'),
68 69 70 71 72
              ],
            ),
          ],
        ),
      ),
73
    );
74 75
  }
}