cupertino_buttons_demo.dart 2.75 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 CupertinoButtonsDemo extends StatefulWidget {
  static const String routeName = '/cupertino/buttons';

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

class _CupertinoButtonDemoState extends State<CupertinoButtonsDemo> {
  int _pressedCount = 0;

  @override
  Widget build(BuildContext context) {
22 23
    return Scaffold(
      appBar: AppBar(
24
        title: const Text('Cupertino Buttons'),
25
        actions: <Widget>[MaterialDemoDocumentationButton(CupertinoButtonsDemo.routeName)],
26
      ),
27
      body: Column(
28
        children: <Widget> [
29
          const Padding(
30 31
            padding: EdgeInsets.all(16.0),
            child: Text(
32 33 34
              'iOS themed buttons are flat. They can have borders or backgrounds but '
              'only when necessary.'
            ),
35
          ),
36 37
          Expanded(
            child: Column(
38 39
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget> [
40
                Text(_pressedCount > 0
41
                    ? 'Button pressed $_pressedCount time${_pressedCount == 1 ? "" : "s"}'
42
                    : ' '),
43
                const Padding(padding: EdgeInsets.all(12.0)),
44
                Align(
45
                  alignment: const Alignment(0.0, -0.2),
46
                  child: Row(
47 48
                    mainAxisSize: MainAxisSize.min,
                    children: <Widget>[
49
                      CupertinoButton(
50
                        child: const Text('Cupertino Button'),
51
                        onPressed: () {
52
                          setState(() { _pressedCount += 1; });
53 54
                        }
                      ),
55
                      const CupertinoButton(
56
                        child: Text('Disabled'),
57 58 59 60 61
                        onPressed: null,
                      ),
                    ],
                  ),
                ),
62
                const Padding(padding: EdgeInsets.all(12.0)),
63
                CupertinoButton(
64
                  child: const Text('With Background'),
65
                  color: CupertinoColors.activeBlue,
66
                  onPressed: () {
67
                    setState(() { _pressedCount += 1; });
68 69
                  }
                ),
70
                const Padding(padding: EdgeInsets.all(12.0)),
71
                const CupertinoButton(
72
                  child: Text('Disabled'),
73
                  color: CupertinoColors.activeBlue,
74 75 76 77 78 79 80 81 82 83
                  onPressed: null,
                ),
              ],
            )
          ),
        ],
      )
    );
  }
}