indexed_stack.dart 1.79 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;
    });
  }

Adam Barth's avatar
Adam Barth committed
22
  List <PopupMenuItem> _buildMenu() {
Hans Muller's avatar
Hans Muller committed
23 24 25 26 27 28 29 30 31
    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) {
Adam Barth's avatar
Adam Barth committed
32
    List <PopupMenuItem> items = _buildMenu();
Hans Muller's avatar
Hans Muller committed
33 34 35 36 37 38
    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,
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 59
    title: 'IndexedStackDemo',
    theme: new ThemeData(
      brightness: ThemeBrightness.light,
      primarySwatch: Colors.blue,
      accentColor: Colors.redAccent[200]
    ),
    routes: {
Adam Barth's avatar
Adam Barth committed
60
      '/': (RouteArguments args) => new IndexedStackDemo(),
Hans Muller's avatar
Hans Muller committed
61 62 63
    }
  ));
}