indexed_stack.dart 1.87 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

class IndexedStackDemo extends StatefulComponent {
  IndexedStackDemoState createState() => new IndexedStackDemoState();
}

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

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

Hixie's avatar
Hixie committed
22
  List<PopupMenuItem> _buildMenu() {
23
    TextStyle style = const TextStyle(fontSize: 18.0, fontWeight: FontWeight.bold);
Hans Muller's avatar
Hans Muller committed
24
    String pad = '';
Hixie's avatar
Hixie committed
25
    return new List<PopupMenuItem>.generate(_itemCount, (int i) {
Hans Muller's avatar
Hans Muller committed
26 27 28 29 30 31
      pad += '-';
      return new PopupMenuItem(value: i, child: new Text('$pad Hello World $i $pad', style: style));
    });
  }

  Widget build(BuildContext context) {
32
    List<PopupMenuItem> items = _buildMenu();
33
    IndexedStack indexedStack = new IndexedStack(children: items, index: _itemIndex, alignment: const FractionalOffset(0.5, 0.0));
Hans Muller's avatar
Hans Muller committed
34 35 36 37 38

    return new Scaffold(
      toolBar: new ToolBar(center: new Text('IndexedStackDemo Demo')),
      body: new GestureDetector(
        onTap: _handleTap,
39 40 41 42 43
        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
44 45 46 47 48 49 50 51
          )
        )
      )
    );
  }
}

void main() {
Adam Barth's avatar
Adam Barth committed
52
  runApp(new MaterialApp(
Hans Muller's avatar
Hans Muller committed
53 54 55 56 57 58
    title: 'IndexedStackDemo',
    theme: new ThemeData(
      brightness: ThemeBrightness.light,
      primarySwatch: Colors.blue,
      accentColor: Colors.redAccent[200]
    ),
Hixie's avatar
Hixie committed
59
    routes: <String, RouteBuilder>{
Adam Barth's avatar
Adam Barth committed
60
      '/': (RouteArguments args) => new IndexedStackDemo(),
Hans Muller's avatar
Hans Muller committed
61 62 63
    }
  ));
}