typography_demo.dart 2.64 KB
Newer Older
Hans Muller's avatar
Hans Muller committed
1 2 3 4 5 6 7
// 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';
import 'package:flutter/widgets.dart';

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

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

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

41
class TypographyDemo extends StatelessWidget {
42 43
  static const String routeName = '/typography';

44
  @override
Hans Muller's avatar
Hans Muller committed
45
  Widget build(BuildContext context) {
46
    final TextTheme textTheme = Theme.of(context).textTheme;
Hans Muller's avatar
Hans Muller committed
47
    final List<Widget> styleItems = <Widget>[
48 49 50 51 52 53 54 55 56 57
      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'),
      new TextStyleItem(name: 'Body 1', style: textTheme.body1, text: 'Reguluar 14sp'),
      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
58 59 60 61
    ];

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

    return new Scaffold(
69
      appBar: new AppBar(title: new Text('Typography')),
Hans Muller's avatar
Hans Muller committed
70 71 72 73
      body: new Block(children: styleItems)
    );
  }
}