tooltip_demo.dart 2.42 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
Hans Muller's avatar
Hans Muller committed
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/material.dart';

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

Hans Muller's avatar
Hans Muller committed
9
const String _introText =
10 11 12
  'Tooltips are short identifying messages that briefly appear in response to '
  'a long press. Tooltip messages are also used by services that make Flutter '
  'apps accessible, like screen readers.';
Hans Muller's avatar
Hans Muller committed
13

14
class TooltipDemo extends StatelessWidget {
15

16
  static const String routeName = '/material/tooltips';
17

18
  @override
Hans Muller's avatar
Hans Muller committed
19 20
  Widget build(BuildContext context) {
    final ThemeData theme = Theme.of(context);
21 22
    return Scaffold(
      appBar: AppBar(
23 24
        title: const Text('Tooltips'),
        actions: <Widget>[MaterialDemoDocumentationButton(routeName)],
Hans Muller's avatar
Hans Muller committed
25
      ),
26
      body: Builder(
Hans Muller's avatar
Hans Muller committed
27
        builder: (BuildContext context) {
28
          return SafeArea(
29 30
            top: false,
            bottom: false,
31
            child: ListView(
32
              children: <Widget>[
33
                Text(_introText, style: theme.textTheme.subtitle1),
34
                Row(
35
                  children: <Widget>[
36
                    Text('Long press the ', style: theme.textTheme.subtitle1),
37
                    Tooltip(
38
                      message: 'call icon',
39
                      child: Icon(
40 41
                        Icons.call,
                        size: 18.0,
42 43
                        color: theme.iconTheme.color,
                      ),
44
                    ),
45
                    Text(' icon.', style: theme.textTheme.subtitle1),
46
                  ],
47
                ),
48 49
                Center(
                  child: IconButton(
50 51 52 53 54 55
                    iconSize: 48.0,
                    icon: const Icon(Icons.call),
                    color: theme.iconTheme.color,
                    tooltip: 'Place a phone call',
                    onPressed: () {
                      Scaffold.of(context).showSnackBar(const SnackBar(
56
                         content: Text('That was an ordinary tap.'),
57
                      ));
58 59 60
                    },
                  ),
                ),
61
              ]
62
              .map<Widget>((Widget widget) {
63
                return Padding(
64
                  padding: const EdgeInsets.only(top: 16.0, left: 16.0, right: 16.0),
65
                  child: widget,
66 67
                );
              })
68
              .toList(),
69
            ),
Hans Muller's avatar
Hans Muller committed
70 71
          );
        }
72
      ),
Hans Muller's avatar
Hans Muller committed
73 74 75
    );
  }
}