main.dart 4.42 KB
Newer Older
1 2 3 4
// Copyright 2015 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.

Eric Seidel's avatar
Eric Seidel committed
5
import 'package:sky/editing/input.dart';
6 7
import 'package:sky/theme/colors.dart' as colors;
import 'package:sky/theme/typography.dart' as typography;
8
import 'package:sky/widgets.dart';
9 10

class Field extends Component {
Eric Seidel's avatar
Eric Seidel committed
11 12 13 14 15 16
  Field({
    Key key,
    this.inputKey,
    this.icon,
    this.placeholder
  }): super(key: key);
17

Eric Seidel's avatar
Eric Seidel committed
18 19 20
  final GlobalKey inputKey;
  final String icon;
  final String placeholder;
21 22 23 24 25

  Widget build() {
    return new Flex([
        new Padding(
          padding: const EdgeDims.symmetric(horizontal: 16.0),
Eric Seidel's avatar
Eric Seidel committed
26
          child: new Icon(type: icon, size: 24)
27
        ),
Eric Seidel's avatar
Eric Seidel committed
28 29 30 31 32 33
        new Flexible(
          child: new Input(
            key: inputKey,
            placeholder: placeholder
          )
        )
34 35 36 37 38 39 40 41
      ],
      direction: FlexDirection.horizontal
    );
  }
}

class AddressBookApp extends App {

42
  Widget buildToolBar(Navigator navigator) {
43 44 45 46 47 48
    return new ToolBar(
        left: new IconButton(icon: "navigation/arrow_back"),
        right: [new IconButton(icon: "navigation/check")]
      );
  }

49
  Widget buildFloatingActionButton(Navigator navigator) {
50 51
    return new FloatingActionButton(
      child: new Icon(type: 'image/photo_camera', size: 24),
52 53
      backgroundColor: Theme.of(this).accentColor,
      onPressed: () {
54
        showDialog(navigator, (navigator) {
55 56 57 58 59 60 61 62 63 64
          return new Dialog(
            title: new Text("Describe your picture"),
            content: new ScrollableBlock([
              new Field(inputKey: fillKey, icon: "editor/format_color_fill", placeholder: "Color"),
              new Field(inputKey: emoticonKey, icon: "editor/insert_emoticon", placeholder: "Emotion"),
            ]),
            onDismiss: navigator.pop,
            actions: [
              new FlatButton(
                child: new Text('DISCARD'),
65
                onPressed: navigator.pop
66 67 68 69 70 71 72 73 74
              ),
              new FlatButton(
                child: new Text('SAVE'),
                onPressed: () {
                  navigator.pop();
                }
              ),
            ]
          );
75
        });
76
      }
77 78 79
    );
  }

Eric Seidel's avatar
Eric Seidel committed
80 81 82 83 84 85
  static final GlobalKey nameKey = new GlobalKey();
  static final GlobalKey phoneKey = new GlobalKey();
  static final GlobalKey emailKey = new GlobalKey();
  static final GlobalKey addressKey = new GlobalKey();
  static final GlobalKey ringtoneKey = new GlobalKey();
  static final GlobalKey noteKey = new GlobalKey();
86 87
  static final GlobalKey fillKey = new GlobalKey();
  static final GlobalKey emoticonKey = new GlobalKey();
Eric Seidel's avatar
Eric Seidel committed
88

89
  Widget buildBody(Navigator navigator) {
90 91 92 93 94 95 96 97
    return new Material(
      child: new ScrollableBlock([
        new AspectRatio(
          aspectRatio: 16.0 / 9.0,
          child: new Container(
            decoration: new BoxDecoration(backgroundColor: colors.Purple[300])
          )
        ),
Eric Seidel's avatar
Eric Seidel committed
98 99 100 101 102 103
        new Field(inputKey: nameKey, icon: "social/person", placeholder: "Name"),
        new Field(inputKey: phoneKey, icon: "communication/phone", placeholder: "Phone"),
        new Field(inputKey: emailKey, icon: "communication/email", placeholder: "Email"),
        new Field(inputKey: addressKey, icon: "maps/place", placeholder: "Address"),
        new Field(inputKey: ringtoneKey, icon: "av/volume_up", placeholder: "Ringtone"),
        new Field(inputKey: noteKey, icon: "content/add", placeholder: "Add note"),
104 105 106 107
      ])
    );
  }

108
  Widget buildMain(Navigator navigator) {
109 110 111 112
    return new Scaffold(
      toolbar: buildToolBar(navigator),
      body: buildBody(navigator),
      floatingActionButton: buildFloatingActionButton(navigator)
113
    );
114 115 116 117 118 119 120 121 122 123 124 125
  }

  NavigationState _navigationState;

  void initState() {
    _navigationState = new NavigationState([
      new Route(
        name: '/',
        builder: (navigator, route) => buildMain(navigator)
      ),
    ]);
    super.initState();
126 127 128 129 130 131 132 133 134 135
  }

  Widget build() {
    ThemeData theme = new ThemeData(
      brightness: ThemeBrightness.light,
      primarySwatch: colors.Teal,
      accentColor: colors.PinkAccent[100]
    );
    return new Theme(
      data: theme,
Eric Seidel's avatar
Eric Seidel committed
136 137 138 139
      child: new DefaultTextStyle(
        style: typography.error, // if you see this, you've forgotten to correctly configure the text style!
        child: new TaskDescription(
          label: 'Address Book',
140
          child: new Navigator(_navigationState)
141
        )
Eric Seidel's avatar
Eric Seidel committed
142 143 144
      )
    );
  }
145 146 147 148 149
}

void main() {
  runApp(new AddressBookApp());
}