Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(362)

Side by Side Diff: sky/sdk/example/widgets/tabs.dart

Issue 1212993003: Add TabNavigator (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Updated tabs example test expectations Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | sky/sdk/lib/widgets/tabs.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 import 'package:sky/theme/colors.dart'; 5 import 'package:sky/painting/text_style.dart';
6 import 'package:sky/theme/typography.dart'; 6 import 'package:sky/theme/typography.dart';
7 import 'package:sky/widgets/basic.dart'; 7 import 'package:sky/widgets/basic.dart';
8 import 'package:sky/widgets/material.dart'; 8 import 'package:sky/widgets/material.dart';
9 import 'package:sky/widgets/scaffold.dart'; 9 import 'package:sky/widgets/scaffold.dart';
10 import 'package:sky/widgets/tabs.dart'; 10 import 'package:sky/widgets/tabs.dart';
11 import 'package:sky/widgets/tool_bar.dart'; 11 import 'package:sky/widgets/tool_bar.dart';
12 import 'package:sky/widgets/widget.dart'; 12 import 'package:sky/widgets/widget.dart';
13 13
14 class TabbedNavigatorApp extends App { 14 class TabbedNavigatorApp extends App {
15 static Iterable<String> items = const <String>["ONE", "TWO", "FREE", "FOUR"]; 15 int selectedIndex = 0;
16 final List<int> navigatorSelections = new List<int>.filled(items.length, 0);
17 16
18 Widget buildTabNavigator(Iterable<TabLabel> labels, int navigatorIndex) { 17 Widget _buildContent(String label) {
19 TabBar tabBar = new TabBar( 18 return new Center(
20 labels: labels.toList(), 19 child: new Text(label, style: const TextStyle(fontSize: 48.0, fontWeight: extraBold))
21 selectedIndex: navigatorSelections[navigatorIndex], 20 );
22 onChanged: (selectionIndex) { 21 }
23 setState(() { 22
24 navigatorSelections[navigatorIndex] = selectionIndex; 23 Widget build() {
25 }); 24 List<TabNavigatorView> views = <TabNavigatorView>[
25 new TabNavigatorView(
26 label: const TabLabel(text: 'STOCKS', icon: 'action/list_white'),
27 builder: () => _buildContent("Stocks")
28 ),
29 new TabNavigatorView(
30 label: const TabLabel(text: 'PORTFOLIO', icon: 'action/account_circle_wh ite'),
31 builder: () => _buildContent("Portfolio")
32 ),
33 new TabNavigatorView(
34 label: const TabLabel(text: 'SUMMARY', icon: 'action/assessment_white'),
35 builder: () => _buildContent("Summary")
36 )
37 ];
38
39 TabNavigator tabNavigator = new TabNavigator(
40 views: views,
41 selectedIndex: selectedIndex,
42 onChanged: (tabIndex) {
43 setState(() { selectedIndex = tabIndex; } );
26 } 44 }
27 ); 45 );
28 46
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 ToolBar toolbar = new ToolBar(
47 center: new Text('Tabbed Navigator', style: white.title) 48 center: new Text('Tabbed Navigator', style: white.title)
48 ); 49 );
49 50
50 return new Scaffold( 51 return new Scaffold(
51 toolbar: toolbar, 52 toolbar: toolbar,
52 body: new Material( 53 body: new Material(child: tabNavigator)
53 child: new Center(child: new Block(tabNavigators.toList())),
54 color: Grey[500]
55 )
56 ); 54 );
57 } 55 }
58 } 56 }
59 57
60 void main() { 58 void main() {
61 runApp(new TabbedNavigatorApp()); 59 runApp(new TabbedNavigatorApp());
62 } 60 }
OLDNEW
« no previous file with comments | « no previous file | sky/sdk/lib/widgets/tabs.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698