selection_controls_demo.dart 2.25 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 SelectionControlsDemo extends StatefulWidget {
8
  @override
9
  _SelectionControlsDemoState createState() => new _SelectionControlsDemoState();
10 11
}

12
class _SelectionControlsDemoState extends State<SelectionControlsDemo> {
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  bool _checkboxValue = false;
  int _radioValue = 0;
  bool _switchValue = false;

  void _setCheckboxValue(bool value) {
    setState(() {
      _checkboxValue = value;
    });
  }

  void _setRadioValue(int value) {
    setState(() {
      _radioValue = value;
    });
  }

  void _setSwitchValue(bool value) {
    setState(() {
      _switchValue = value;
    });
  }

35
  @override
36 37
  Widget build(BuildContext context) {
    return new Scaffold(
38
      appBar: new AppBar(title: new Text('Selection controls')),
39 40 41 42 43 44 45 46
      body: new Column(
        children: <Widget>[
          new Row(
            children: <Widget>[
              new Checkbox(value: _checkboxValue, onChanged: _setCheckboxValue),
              new Checkbox(value: false), // Disabled
              new Checkbox(value: true), // Disabled
            ],
47
            mainAxisAlignment: MainAxisAlignment.spaceAround
48 49 50 51 52 53 54 55 56
          ),
          new Row(
            children: <int>[0, 1, 2].map((int i) {
              return new Radio<int>(
                value: i,
                groupValue: _radioValue,
                onChanged: _setRadioValue
              );
            }).toList(),
57
            mainAxisAlignment: MainAxisAlignment.spaceAround
58 59 60 61 62
          ),
          new Row(
            children: <int>[0, 1].map((int i) {
              return new Radio<int>(value: i, groupValue: 0); // Disabled
            }).toList(),
63
            mainAxisAlignment: MainAxisAlignment.spaceAround
64 65 66 67 68 69 70
          ),
          new Row(
            children: <Widget>[
              new Switch(value: _switchValue, onChanged: _setSwitchValue),
              new Switch(value: false), // Disabled
              new Switch(value: true), // Disabled
            ],
71
            mainAxisAlignment: MainAxisAlignment.spaceAround
72 73
          ),
        ],
74
        mainAxisAlignment: MainAxisAlignment.spaceAround
75 76 77 78
      )
    );
  }
}