OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 import 'package:sky/theme/colors.dart'; |
| 6 import 'package:sky/theme/typography.dart'; |
| 7 import 'package:sky/widgets/basic.dart'; |
| 8 import 'package:sky/widgets/material.dart'; |
| 9 import 'package:sky/widgets/scaffold.dart'; |
| 10 import 'package:sky/widgets/tabs.dart'; |
| 11 import 'package:sky/widgets/tool_bar.dart'; |
| 12 import 'package:sky/widgets/widget.dart'; |
| 13 |
| 14 class TabbedNavigatorApp extends App { |
| 15 static Iterable<String> items = const <String>["ONE", "TWO", "FREE", "FOUR"]; |
| 16 final List<int> navigatorSelections = new List<int>.filled(items.length, 0); |
| 17 |
| 18 Widget buildTabNavigator(Iterable<TabLabel> labels, int navigatorIndex) { |
| 19 TabBar tabBar = new TabBar( |
| 20 labels: labels.toList(), |
| 21 selectedIndex: navigatorSelections[navigatorIndex], |
| 22 onChanged: (selectionIndex) { |
| 23 setState(() { |
| 24 navigatorSelections[navigatorIndex] = selectionIndex; |
| 25 }); |
| 26 } |
| 27 ); |
| 28 |
| 29 return new Container(child: tabBar, margin: new EdgeDims.only(bottom: 16.0))
; |
| 30 } |
| 31 |
| 32 Widget build() { |
| 33 Iterable<TabLabel> textLabels = items |
| 34 .map((s) => new TabLabel(text: "ITEM " + s)); |
| 35 |
| 36 Iterable<TabLabel> iconLabels = items |
| 37 .map((s) => new TabLabel(icon: 'action/search_white')); |
| 38 |
| 39 Iterable<TabLabel> textAndIconLabels = items |
| 40 .map((s) => new TabLabel(text: "ITEM " + s, icon: 'action/search_white')); |
| 41 |
| 42 var navigatorIndex = 0; |
| 43 Iterable<Widget> tabNavigators = [textLabels, iconLabels, textAndIconLabels] |
| 44 .map((labels) => buildTabNavigator(labels, navigatorIndex++)); |
| 45 |
| 46 ToolBar toolbar = new ToolBar( |
| 47 center: new Text('Tabbed Navigator', style: white.title), |
| 48 backgroundColor: Blue[500]); |
| 49 |
| 50 return new Scaffold( |
| 51 toolbar: toolbar, |
| 52 body: new Material( |
| 53 child: new Center(child: new Block(tabNavigators.toList())), |
| 54 color: Grey[500] |
| 55 ) |
| 56 ); |
| 57 } |
| 58 } |
| 59 |
| 60 void main() { |
| 61 runApp(new TabbedNavigatorApp()); |
| 62 } |
OLD | NEW |