tooltip_demo.dart 2.47 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
  const TooltipDemo({super.key});
16

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

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