main.dart 2.93 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.

5
import 'package:flutter/material.dart';
6

Adam Barth's avatar
Adam Barth committed
7
class Field extends StatelessComponent {
Eric Seidel's avatar
Eric Seidel committed
8 9 10 11 12
  Field({
    Key key,
    this.inputKey,
    this.icon,
    this.placeholder
13
  }) : super(key: key);
14

Eric Seidel's avatar
Eric Seidel committed
15 16 17
  final GlobalKey inputKey;
  final String icon;
  final String placeholder;
18

Adam Barth's avatar
Adam Barth committed
19
  Widget build(BuildContext context) {
Hixie's avatar
Hixie committed
20
    return new Row(<Widget>[
21 22
        new Padding(
          padding: const EdgeDims.symmetric(horizontal: 16.0),
23
          child: new Icon(icon: icon)
24
        ),
Eric Seidel's avatar
Eric Seidel committed
25 26 27 28 29 30
        new Flexible(
          child: new Input(
            key: inputKey,
            placeholder: placeholder
          )
        )
31
      ]
32 33 34 35
    );
  }
}

Adam Barth's avatar
Adam Barth committed
36 37
class AddressBookHome extends StatelessComponent {
  Widget buildToolBar(BuildContext context) {
38
    return new ToolBar(
39 40
      right: <Widget>[new IconButton(icon: "navigation/check")]
    );
41 42
  }

Adam Barth's avatar
Adam Barth committed
43
  Widget buildFloatingActionButton(BuildContext context) {
44
    return new FloatingActionButton(
45
      child: new Icon(icon: 'image/photo_camera'),
Adam Barth's avatar
Adam Barth committed
46
      backgroundColor: Theme.of(context).accentColor
47 48 49
    );
  }

50 51 52 53 54 55
  static final GlobalKey nameKey = new GlobalKey(debugLabel: 'name field');
  static final GlobalKey phoneKey = new GlobalKey(debugLabel: 'phone field');
  static final GlobalKey emailKey = new GlobalKey(debugLabel: 'email field');
  static final GlobalKey addressKey = new GlobalKey(debugLabel: 'address field');
  static final GlobalKey ringtoneKey = new GlobalKey(debugLabel: 'ringtone field');
  static final GlobalKey noteKey = new GlobalKey(debugLabel: 'note field');
Eric Seidel's avatar
Eric Seidel committed
56

Adam Barth's avatar
Adam Barth committed
57
  Widget buildBody(BuildContext context) {
Hixie's avatar
Hixie committed
58
    return new Block(<Widget>[
59 60 61 62 63 64 65 66 67 68 69 70 71
      new AspectRatio(
        aspectRatio: 16.0 / 9.0,
        child: new Container(
          decoration: new BoxDecoration(backgroundColor: Colors.purple[300])
        )
      ),
      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"),
    ]);
72 73
  }

Adam Barth's avatar
Adam Barth committed
74
  Widget build(BuildContext context) {
75
    return new Scaffold(
Adam Barth's avatar
Adam Barth committed
76
      toolBar: buildToolBar(context),
Adam Barth's avatar
Adam Barth committed
77 78
      body: buildBody(context),
      floatingActionButton: buildFloatingActionButton(context)
Eric Seidel's avatar
Eric Seidel committed
79 80
    );
  }
81 82
}

Adam Barth's avatar
Adam Barth committed
83 84 85 86 87 88
final ThemeData theme = new ThemeData(
  brightness: ThemeBrightness.light,
  primarySwatch: Colors.teal,
  accentColor: Colors.pinkAccent[100]
);

89
void main() {
Adam Barth's avatar
Adam Barth committed
90
  runApp(new MaterialApp(
Adam Barth's avatar
Adam Barth committed
91 92 93
    title: 'Address Book',
    theme: theme,
    routes: <String, RouteBuilder>{
Adam Barth's avatar
Adam Barth committed
94
      '/': (RouteArguments args) => new AddressBookHome()
Adam Barth's avatar
Adam Barth committed
95 96
    }
  ));
97
}