indexed_stack.dart 1.93 KB
Newer Older
Hans Muller's avatar
Hans Muller committed
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 6
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
Hans Muller's avatar
Hans Muller committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

class IndexedStackDemo extends StatefulComponent {
  IndexedStackDemo({ this.navigator });

  final NavigatorState navigator;

  IndexedStackDemoState createState() => new IndexedStackDemoState();
}

class IndexedStackDemoState extends State<IndexedStackDemo> {
  int _itemCount = 7;
  int _itemIndex = 0;

  void _handleTap() {
    setState(() {
      _itemIndex = (_itemIndex + 1) % _itemCount;
    });
  }

  List <PopupMenuItem> _buildMenu(NavigatorState navigator) {
    TextStyle style = const TextStyle(fontSize: 18.0, fontWeight: bold);
    String pad = '';
    return new List.generate(_itemCount, (int i) {
      pad += '-';
      return new PopupMenuItem(value: i, child: new Text('$pad Hello World $i $pad', style: style));
    });
  }

  Widget build(BuildContext context) {
    List <PopupMenuItem> items = _buildMenu(config.navigator);
    IndexedStack indexedStack = new IndexedStack(items, index: _itemIndex, horizontalAlignment: 0.5);

    return new Scaffold(
      toolBar: new ToolBar(center: new Text('IndexedStackDemo Demo')),
      body: new GestureDetector(
        onTap: _handleTap,
43 44 45 46 47
        child: new Center(
          child: new Container(
            child: indexedStack,
            padding: const EdgeDims.all(8.0),
            decoration: new BoxDecoration(border: new Border.all(color: Theme.of(context).accentColor))
Hans Muller's avatar
Hans Muller committed
48 49 50 51 52 53 54 55
          )
        )
      )
    );
  }
}

void main() {
Adam Barth's avatar
Adam Barth committed
56
  runApp(new MaterialApp(
Hans Muller's avatar
Hans Muller committed
57 58 59 60 61 62 63 64 65 66 67
    title: 'IndexedStackDemo',
    theme: new ThemeData(
      brightness: ThemeBrightness.light,
      primarySwatch: Colors.blue,
      accentColor: Colors.redAccent[200]
    ),
    routes: {
      '/': (RouteArguments args) => new IndexedStackDemo(navigator: args.navigator),
    }
  ));
}