flutter/examples/widgets/indexed_stack.dart
Hans Muller 09d26302cb IndexedStack
Added horizontal and vertical alignment properties to Stack so that the origin of non-positioned children can be specified. Currently all of the non-positioned children just end up with their top-left at 0,0. Now, for example, you can center the children by specifying verticalAlignment: 0.5, horizontalAlignment: 0.5.

Added IndexedStack which only paints the stack child specified by the index property. Since it's a Stack, it's as big as the biggest non-positioned child. This component will be essential for building mobile drop down menus.

Added a (likely temporary) example that demonstrates IndexedStack.
2015-10-08 10:21:24 -07:00

72 lines
2.1 KiB
Dart

// 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.
import 'package:sky/material.dart';
import 'package:sky/rendering.dart';
import 'package:sky/widgets.dart';
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,
child: new Container(
decoration: new BoxDecoration(backgroundColor: Theme.of(context).primarySwatch[50]),
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))
)
)
)
)
);
}
}
void main() {
runApp(new App(
title: 'IndexedStackDemo',
theme: new ThemeData(
brightness: ThemeBrightness.light,
primarySwatch: Colors.blue,
accentColor: Colors.redAccent[200]
),
routes: {
'/': (RouteArguments args) => new IndexedStackDemo(navigator: args.navigator),
}
));
}