navigation.dart 2.64 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

7 8
class Home extends StatelessComponent {
  Widget build(BuildContext context) {
Hixie's avatar
Hixie committed
9 10 11 12 13 14 15 16 17
    return new Material(
      child: new Center(
        child: new Block(<Widget>[
            new Text(
              'You are at home.',
              style: Theme.of(context).text.display2.copyWith(textAlign: TextAlign.center)
            ),
            new RaisedButton(
              child: new Text('GO SHOPPING'),
Hixie's avatar
Hixie committed
18
              onPressed: () => Navigator.pushNamed(context, '/shopping')
Hixie's avatar
Hixie committed
19 20 21
            ),
            new RaisedButton(
              child: new Text('START ADVENTURE'),
Hixie's avatar
Hixie committed
22
              onPressed: () => Navigator.pushNamed(context, '/adventure')
Hixie's avatar
Hixie committed
23 24 25 26
            )
          ],
          padding: const EdgeDims.all(30.0)
        )
27 28 29 30 31 32 33
      )
    );
  }
}

class Shopping extends StatelessComponent {
  Widget build(BuildContext context) {
Hixie's avatar
Hixie committed
34 35 36 37 38 39 40 41 42 43
    return new Material(
      color: Colors.deepPurple[300],
      child: new Center(
        child: new Block(<Widget>[
            new Text(
              'Village Shop',
              style: Theme.of(context).text.display2.copyWith(textAlign: TextAlign.center)
            ),
            new RaisedButton(
              child: new Text('RETURN HOME'),
Hixie's avatar
Hixie committed
44
              onPressed: () => Navigator.pop(context)
Hixie's avatar
Hixie committed
45 46 47
            ),
            new RaisedButton(
              child: new Text('GO TO DUNGEON'),
Hixie's avatar
Hixie committed
48
              onPressed: () => Navigator.pushNamed(context, '/adventure')
Hixie's avatar
Hixie committed
49 50 51 52
            )
          ],
          padding: const EdgeDims.all(30.0)
        )
53 54 55 56 57 58 59
      )
    );
  }
}

class Adventure extends StatelessComponent {
  Widget build(BuildContext context) {
Hixie's avatar
Hixie committed
60 61 62 63 64 65 66 67 68 69
    return new Material(
      color: Colors.red[300],
      child: new Center(
        child: new Block(<Widget>[
            new Text(
              'Monster\'s Lair',
              style: Theme.of(context).text.display2.copyWith(textAlign: TextAlign.center)
            ),
            new RaisedButton(
              child: new Text('RUN!!!'),
Hixie's avatar
Hixie committed
70
              onPressed: () => Navigator.pop(context)
Hixie's avatar
Hixie committed
71 72 73 74
            )
          ],
          padding: const EdgeDims.all(30.0)
        )
75 76 77 78 79
      )
    );
  }
}

80
final Map<String, RouteBuilder> routes = <String, RouteBuilder>{
81 82 83
  '/': (_) => new Home(),
  '/shopping': (_) => new Shopping(),
  '/adventure': (_) => new Adventure(),
84
};
85

86 87 88 89
final ThemeData theme = new ThemeData(
  brightness: ThemeBrightness.light,
  primarySwatch: Colors.purple
);
90 91

void main() {
Adam Barth's avatar
Adam Barth committed
92
  runApp(new MaterialApp(
93 94 95 96
    title: 'Navigation Example',
    theme: theme,
    routes: routes
  ));
97
}