cupertino_switch_demo.dart 2.79 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6
// 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';

7 8
import '../../gallery/demo.dart';

9 10 11 12
class CupertinoSwitchDemo extends StatefulWidget {
  static const String routeName = '/cupertino/switch';

  @override
13
  _CupertinoSwitchDemoState createState() => _CupertinoSwitchDemoState();
14 15 16 17 18 19 20 21
}

class _CupertinoSwitchDemoState extends State<CupertinoSwitchDemo> {

  bool _switchValue = false;

  @override
  Widget build(BuildContext context) {
xster's avatar
xster committed
22 23 24 25 26 27 28 29
    return CupertinoPageScaffold(
      navigationBar: CupertinoNavigationBar(
        middle: const Text('Switch'),
        // We're specifying a back label here because the previous page is a
        // Material page. CupertinoPageRoutes could auto-populate these back
        // labels.
        previousPageTitle: 'Cupertino',
        trailing: CupertinoDemoDocumentationButton(CupertinoSwitchDemo.routeName),
30
      ),
xster's avatar
xster committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
      child: DefaultTextStyle(
        style: CupertinoTheme.of(context).textTheme.textStyle,
        child: SafeArea(
          child: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: <Widget>[
                Semantics(
                  container: true,
                  child: Column(
                    children: <Widget>[
                      CupertinoSwitch(
                        value: _switchValue,
                        onChanged: (bool value) {
                          setState(() {
                            _switchValue = value;
                          });
                        },
                      ),
50 51
                      Text(
                        "Enabled - ${_switchValue ? "On" : "Off"}"
xster's avatar
xster committed
52 53
                      ),
                    ],
54
                  ),
xster's avatar
xster committed
55 56 57 58 59 60 61 62 63 64
                ),
                Semantics(
                  container: true,
                  child: Column(
                    children: const <Widget>[
                      CupertinoSwitch(
                        value: true,
                        onChanged: null,
                      ),
                      Text(
65
                        'Disabled - On'
xster's avatar
xster committed
66 67
                      ),
                    ],
68
                  ),
xster's avatar
xster committed
69 70 71 72 73 74 75 76 77 78
                ),
                Semantics(
                  container: true,
                  child: Column(
                    children: const <Widget>[
                      CupertinoSwitch(
                        value: false,
                        onChanged: null,
                      ),
                      Text(
79
                        'Disabled - Off'
xster's avatar
xster committed
80 81
                      ),
                    ],
82
                  ),
xster's avatar
xster committed
83 84
                ),
              ],
85
            ),
xster's avatar
xster committed
86
          ),
87 88 89 90 91
        ),
      ),
    );
  }
}