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

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

Issue 1212993003: Add TabNavigator (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: 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') | sky/sdk/lib/widgets/tabs.dart » ('J')
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/painting/text_style.dart';
5 import 'package:sky/theme/colors.dart'; 6 import 'package:sky/theme/colors.dart';
6 import 'package:sky/theme/typography.dart'; 7 import 'package:sky/theme/typography.dart';
7 import 'package:sky/widgets/basic.dart'; 8 import 'package:sky/widgets/basic.dart';
8 import 'package:sky/widgets/material.dart'; 9 import 'package:sky/widgets/material.dart';
9 import 'package:sky/widgets/scaffold.dart'; 10 import 'package:sky/widgets/scaffold.dart';
10 import 'package:sky/widgets/tabs.dart'; 11 import 'package:sky/widgets/tabs.dart';
11 import 'package:sky/widgets/tool_bar.dart'; 12 import 'package:sky/widgets/tool_bar.dart';
12 import 'package:sky/widgets/widget.dart'; 13 import 'package:sky/widgets/widget.dart';
13 14
14 class TabbedNavigatorApp extends App { 15 class TabbedNavigatorApp extends App {
15 static Iterable<String> items = const <String>["ONE", "TWO", "FREE", "FOUR"]; 16 Widget _buildContent(String label) {
16 final List<int> navigatorSelections = new List<int>.filled(items.length, 0); 17 return new Center(
17 18 child: new Text(label, style: const TextStyle(fontSize: 48.0, fontWeight: extraBold))
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 ); 19 );
28
29 return new Container(child: tabBar, margin: new EdgeDims.only(bottom: 16.0)) ;
30 } 20 }
31 21
32 Widget build() { 22 Widget build() {
33 Iterable<TabLabel> textLabels = items 23 List<TabNavigatorView> views = <TabNavigatorView>[
34 .map((s) => new TabLabel(text: "ITEM " + s)); 24 new TabNavigatorView(
35 25 label: const TabLabel(text: 'STOCKS', icon: 'action/list_white'),
36 Iterable<TabLabel> iconLabels = items 26 content: () => _buildContent("Stocks")
37 .map((s) => new TabLabel(icon: 'action/search_white')); 27 ),
38 28 new TabNavigatorView(
39 Iterable<TabLabel> textAndIconLabels = items 29 label: const TabLabel(text: 'PORTFOLIO', icon: 'action/account_circle_wh ite'),
40 .map((s) => new TabLabel(text: "ITEM " + s, icon: 'action/search_white')); 30 content: () => _buildContent("Portfolio")
41 31 ),
42 var navigatorIndex = 0; 32 new TabNavigatorView(
43 Iterable<Widget> tabNavigators = [textLabels, iconLabels, textAndIconLabels] 33 label: const TabLabel(text: 'SUMMARY', icon: 'action/assessment_white'),
44 .map((labels) => buildTabNavigator(labels, navigatorIndex++)); 34 content: () => _buildContent("Summary")
35 )
36 ];
45 37
46 ToolBar toolbar = new ToolBar( 38 ToolBar toolbar = new ToolBar(
47 center: new Text('Tabbed Navigator', style: white.title) 39 center: new Text('Tabbed Navigator', style: white.title)
48 ); 40 );
49 41
50 return new Scaffold( 42 return new Scaffold(
51 toolbar: toolbar, 43 toolbar: toolbar,
52 body: new Material( 44 body: new Material(child: new TabNavigator(views: views))
53 child: new Center(child: new Block(tabNavigators.toList())),
54 color: Grey[500]
55 )
56 ); 45 );
57 } 46 }
58 } 47 }
59 48
60 void main() { 49 void main() {
61 runApp(new TabbedNavigatorApp()); 50 runApp(new TabbedNavigatorApp());
62 } 51 }
OLDNEW
« no previous file with comments | « no previous file | sky/sdk/lib/widgets/tabs.dart » ('j') | sky/sdk/lib/widgets/tabs.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698