navigation.dart 1.96 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
final Map<String, RouteBuilder> routes = <String, RouteBuilder>{
8
  '/': (RouteArguments args) => new Container(
9 10 11 12 13 14
    padding: const EdgeDims.all(30.0),
    decoration: new BoxDecoration(backgroundColor: const Color(0xFFCCCCCC)),
    child: new Column([
      new Text("You are at home"),
      new RaisedButton(
        child: new Text('GO SHOPPING'),
15
        onPressed: () => args.navigator.pushNamed('/shopping')
16 17 18
      ),
      new RaisedButton(
        child: new Text('START ADVENTURE'),
19
        onPressed: () => args.navigator.pushNamed('/adventure')
20 21
      )],
      justifyContent: FlexJustifyContent.center
22 23
    )
  ),
24
  '/shopping': (RouteArguments args) => new Container(
25 26 27 28 29 30
    padding: const EdgeDims.all(20.0),
    decoration: new BoxDecoration(backgroundColor: const Color(0xFFBF5FFF)),
    child: new Column([
      new Text("Village Shop"),
      new RaisedButton(
        child: new Text('RETURN HOME'),
31
        onPressed: () => args.navigator.pop()
32 33 34
      ),
      new RaisedButton(
        child: new Text('GO TO DUNGEON'),
35
        onPressed: () => args.navigator.pushNamed('/adventure')
36 37
      )],
      justifyContent: FlexJustifyContent.center
38 39
    )
  ),
40
  '/adventure': (RouteArguments args) => new Container(
41 42 43 44 45 46
    padding: const EdgeDims.all(20.0),
    decoration: new BoxDecoration(backgroundColor: const Color(0xFFDC143C)),
    child: new Column([
      new Text("Monster's Lair"),
      new RaisedButton(
        child: new Text('RUN!!!'),
47
        onPressed: () => args.navigator.pop()
48 49
      )],
      justifyContent: FlexJustifyContent.center
50 51
    )
  )
52
};
53

54 55 56 57
final ThemeData theme = new ThemeData(
  brightness: ThemeBrightness.light,
  primarySwatch: Colors.purple
);
58 59

void main() {
Adam Barth's avatar
Adam Barth committed
60
  runApp(new MaterialApp(
61 62 63 64
    title: 'Navigation Example',
    theme: theme,
    routes: routes
  ));
65
}