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