typography_demo.dart 2.7 KB
Newer Older
Hans Muller's avatar
Hans Muller committed
1 2 3 4
// 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.

5
import 'package:flutter/foundation.dart';
Hans Muller's avatar
Hans Muller committed
6 7
import 'package:flutter/material.dart';

8
class TextStyleItem extends StatelessWidget {
9
  const TextStyleItem({
10 11 12 13
    Key key,
    @required this.name,
    @required this.style,
    @required this.text,
14 15 16 17
  }) : assert(name != null),
       assert(style != null),
       assert(text != null),
       super(key: key);
Hans Muller's avatar
Hans Muller committed
18 19 20 21 22

  final String name;
  final TextStyle style;
  final String text;

23
  @override
Hans Muller's avatar
Hans Muller committed
24 25
  Widget build(BuildContext context) {
    final ThemeData theme = Theme.of(context);
26
    final TextStyle nameStyle = theme.textTheme.caption.copyWith(color: theme.textTheme.caption.color);
Hans Muller's avatar
Hans Muller committed
27
    return new Padding(
28
      padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 16.0),
Hans Muller's avatar
Hans Muller committed
29
      child: new Row(
30
        crossAxisAlignment: CrossAxisAlignment.start,
Hans Muller's avatar
Hans Muller committed
31 32
        children: <Widget>[
          new SizedBox(
33
            width: 72.0,
Hans Muller's avatar
Hans Muller committed
34 35
            child: new Text(name, style: nameStyle)
          ),
36
          new Expanded(
37
            child: new Text(text, style: style.copyWith(height: 1.0))
Hans Muller's avatar
Hans Muller committed
38 39 40 41 42 43 44
          )
        ]
      )
    );
  }
}

45
class TypographyDemo extends StatelessWidget {
46 47
  static const String routeName = '/typography';

48
  @override
Hans Muller's avatar
Hans Muller committed
49
  Widget build(BuildContext context) {
50
    final TextTheme textTheme = Theme.of(context).textTheme;
Hans Muller's avatar
Hans Muller committed
51
    final List<Widget> styleItems = <Widget>[
52 53 54 55 56 57 58
      new TextStyleItem(name: 'Display 3', style: textTheme.display3, text: 'Regular 56sp'),
      new TextStyleItem(name: 'Display 2', style: textTheme.display2, text: 'Regular 45sp'),
      new TextStyleItem(name: 'Display 1', style: textTheme.display1, text: 'Regular 34sp'),
      new TextStyleItem(name: 'Headline', style: textTheme.headline, text: 'Regular 24sp'),
      new TextStyleItem(name: 'Title', style: textTheme.title, text: 'Medium 20sp'),
      new TextStyleItem(name: 'Subheading', style: textTheme.subhead, text: 'Regular 16sp'),
      new TextStyleItem(name: 'Body 2', style: textTheme.body2, text: 'Medium 14sp'),
Ian Hickson's avatar
Ian Hickson committed
59
      new TextStyleItem(name: 'Body 1', style: textTheme.body1, text: 'Regular 14sp'),
60 61
      new TextStyleItem(name: 'Caption', style: textTheme.caption, text: 'Regular 12sp'),
      new TextStyleItem(name: 'Button', style: textTheme.button, text: 'MEDIUM (ALL CAPS) 14sp')
Hans Muller's avatar
Hans Muller committed
62 63 64 65
    ];

    if (MediaQuery.of(context).size.width > 500.0) {
      styleItems.insert(0, new TextStyleItem(
66
        name: 'Display 4',
Hans Muller's avatar
Hans Muller committed
67 68 69 70 71 72
        style: textTheme.display4,
        text: 'Light 112sp'
      ));
    }

    return new Scaffold(
73
      appBar: new AppBar(title: const Text('Typography')),
74
      body: new ListView(children: styleItems)
Hans Muller's avatar
Hans Muller committed
75 76 77
    );
  }
}