tooltip_demo.dart 2.16 KB
Newer Older
Hans Muller's avatar
Hans Muller committed
1 2 3 4 5 6 7 8 9 10 11
// Copyright 2016 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/material.dart';

const String _introText =
  "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.";

12
class TooltipDemo extends StatelessWidget {
13

14
  static const String routeName = '/tooltips';
15

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