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

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

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

  @override
  Widget build(BuildContext context) {
xster's avatar
xster committed
21 22 23 24 25 26 27 28
    return CupertinoPageScaffold(
      navigationBar: CupertinoNavigationBar(
        middle: const Text('Buttons'),
        // 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(CupertinoButtonsDemo.routeName),
29
      ),
xster's avatar
xster committed
30 31 32 33 34 35 36 37 38 39
      child: DefaultTextStyle(
        style: CupertinoTheme.of(context).textTheme.textStyle,
        child: SafeArea(
          child: Column(
            children: <Widget>[
              const Padding(
                padding: EdgeInsets.all(16.0),
                child: Text(
                  'iOS themed buttons are flat. They can have borders or backgrounds but '
                  'only when necessary.'
40
                ),
xster's avatar
xster committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
              ),
              Expanded(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget> [
                    Text(_pressedCount > 0
                        ? 'Button pressed $_pressedCount time${_pressedCount == 1 ? "" : "s"}'
                        : ' '),
                    const Padding(padding: EdgeInsets.all(12.0)),
                    Align(
                      alignment: const Alignment(0.0, -0.2),
                      child: Row(
                        mainAxisSize: MainAxisSize.min,
                        children: <Widget>[
                          CupertinoButton(
                            child: const Text('Cupertino Button'),
                            onPressed: () {
                              setState(() { _pressedCount += 1; });
59
                            },
xster's avatar
xster committed
60 61 62 63 64 65 66 67 68 69 70 71 72
                          ),
                          const CupertinoButton(
                            child: Text('Disabled'),
                            onPressed: null,
                          ),
                        ],
                      ),
                    ),
                    const Padding(padding: EdgeInsets.all(12.0)),
                    CupertinoButton.filled(
                      child: const Text('With Background'),
                      onPressed: () {
                        setState(() { _pressedCount += 1; });
73
                      },
xster's avatar
xster committed
74 75 76 77 78 79 80
                    ),
                    const Padding(padding: EdgeInsets.all(12.0)),
                    const CupertinoButton.filled(
                      child: Text('Disabled'),
                      onPressed: null,
                    ),
                  ],
81
                ),
xster's avatar
xster committed
82 83
              ),
            ],
84
          ),
xster's avatar
xster committed
85
        ),
86
      ),
87 88 89
    );
  }
}