cupertino_switch_demo.dart 1.87 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
// Copyright 2017 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/cupertino.dart';
import 'package:flutter/material.dart';

class CupertinoSwitchDemo extends StatefulWidget {
  static const String routeName = '/cupertino/switch';

  @override
  _CupertinoSwitchDemoState createState() => new _CupertinoSwitchDemoState();
}

class _CupertinoSwitchDemoState extends State<CupertinoSwitchDemo> {

  bool _switchValue = false;

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
23
        title: const Text('Cupertino Switch'),
24 25
      ),
      body: new Center(
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
        child: new Column(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: <Widget>[
            new Column(
              children: <Widget>[
                new CupertinoSwitch(
                  value: _switchValue,
                  onChanged: (bool value) {
                    setState(() {
                      _switchValue = value;
                    });
                  },
                ),
                const Text(
                  'Active'
                ),
              ],
            ),
            new Column(
45 46
              children: const <Widget>[
                const CupertinoSwitch(
47 48 49 50 51 52 53 54 55
                  value: true,
                  onChanged: null,
                ),
                const Text(
                  'Disabled'
                ),
              ],
            ),
            new Column(
56 57
              children: const <Widget>[
                const CupertinoSwitch(
58 59 60 61 62 63 64 65 66
                  value: false,
                  onChanged: null,
                ),
                const Text(
                  'Disabled'
                ),
              ],
            ),
          ],
67 68 69 70 71
        ),
      ),
    );
  }
}