toggle_controls_demo.dart 2.21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 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 72 73 74 75 76
// 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 ToggleControlsDemo extends StatefulComponent {
  _ToggleControlsDemoState createState() => new _ToggleControlsDemoState();
}

class _ToggleControlsDemoState extends State<ToggleControlsDemo> {
  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;
    });
  }

  Widget build(BuildContext context) {
    return new Scaffold(
      toolBar: new ToolBar(center: new Text("Selection Controls")),
      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
            ],
            justifyContent: FlexJustifyContent.spaceAround
          ),
          new Row(
            children: <int>[0, 1, 2].map((int i) {
              return new Radio<int>(
                value: i,
                groupValue: _radioValue,
                onChanged: _setRadioValue
              );
            }).toList(),
            justifyContent: FlexJustifyContent.spaceAround
          ),
          new Row(
            children: <int>[0, 1].map((int i) {
              return new Radio<int>(value: i, groupValue: 0); // Disabled
            }).toList(),
            justifyContent: FlexJustifyContent.spaceAround
          ),
          new Row(
            children: <Widget>[
              new Switch(value: _switchValue, onChanged: _setSwitchValue),
              new Switch(value: false), // Disabled
              new Switch(value: true), // Disabled
            ],
            justifyContent: FlexJustifyContent.spaceAround
          ),
        ],
        justifyContent: FlexJustifyContent.spaceAround
      )
    );
  }
}