cupertino_slider_demo.dart 1.96 KB
Newer Older
1
// Copyright 2017 The Chromium Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'package:flutter/cupertino.dart';
6 7
import 'package:flutter/material.dart';

8 9
class CupertinoSliderDemo extends StatefulWidget {
  static const String routeName = '/cupertino/slider';
10

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

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

19
  @override
20
  Widget build(BuildContext context) {
21
    return new Scaffold(
22
      appBar: new AppBar(
23
        title: const Text('Cupertino Sliders'),
24
      ),
25 26 27 28 29 30 31
      body: new Center(
        child: new Column(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: <Widget>[
            new Column(
              mainAxisSize: MainAxisSize.min,
              children: <Widget> [
32
                new CupertinoSlider(
33 34 35 36 37 38 39 40 41
                  value: _value,
                  min: 0.0,
                  max: 100.0,
                  onChanged: (double value) {
                    setState(() {
                      _value = value;
                    });
                  }
                ),
Ian Hickson's avatar
Ian Hickson committed
42
                new Text('Cupertino Continuous: ${_value.toStringAsFixed(1)}'),
43 44 45 46 47
              ]
            ),
            new Column(
              mainAxisSize: MainAxisSize.min,
              children: <Widget> [
48
                new CupertinoSlider(
49 50 51 52 53 54 55 56 57 58
                  value: _discreteValue,
                  min: 0.0,
                  max: 100.0,
                  divisions: 5,
                  onChanged: (double value) {
                    setState(() {
                      _discreteValue = value;
                    });
                  }
                ),
Ian Hickson's avatar
Ian Hickson committed
59
                new Text('Cupertino Discrete: $_discreteValue'),
60
              ]
61 62 63 64
            ),
          ],
        ),
      ),
65
    );
66 67
  }
}