cupertino_switch_demo.dart 2.23 KB
Newer Older
1 2 3 4 5 6 7
// 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';

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

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

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

class _CupertinoSwitchDemoState extends State<CupertinoSwitchDemo> {

  bool _switchValue = false;

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