Skip to content

Commit 9eebbce

Browse files
authored
Add options to tabs demo (#290)
1 parent 5fe2c22 commit 9eebbce

File tree

7 files changed

+386
-9
lines changed

7 files changed

+386
-9
lines changed

gallery/gallery/lib/codeviewer/code_segments.dart

Lines changed: 268 additions & 3 deletions
Large diffs are not rendered by default.

gallery/gallery/lib/data/demos.dart

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -524,11 +524,18 @@ List<GalleryDemo> materialDemos(BuildContext context) {
524524
subtitle: localizations.demoTabsSubtitle,
525525
configurations: [
526526
GalleryDemoConfiguration(
527-
title: localizations.demoTabsTitle,
527+
title: localizations.demoTabsScrollingTitle,
528528
description: localizations.demoTabsDescription,
529-
documentationUrl: '$_docsBaseUrl/material/TabBarView-class.html',
530-
buildRoute: (context) => TabsDemo(),
531-
code: CodeSegments.tabsDemo,
529+
documentationUrl: '$_docsBaseUrl/material/TabBar-class.html',
530+
buildRoute: (context) => TabsDemo(type: TabsDemoType.scrollable),
531+
code: CodeSegments.tabsScrollableDemo,
532+
),
533+
GalleryDemoConfiguration(
534+
title: localizations.demoTabsNonScrollingTitle,
535+
description: localizations.demoTabsDescription,
536+
documentationUrl: '$_docsBaseUrl/material/TabBar-class.html',
537+
buildRoute: (context) => TabsDemo(type: TabsDemoType.nonScrollable),
538+
code: CodeSegments.tabsNonScrollableDemo,
532539
),
533540
],
534541
),

gallery/gallery/lib/demos/material/tabs_demo.dart

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,33 @@
55
import 'package:flutter/material.dart';
66
import 'package:gallery/l10n/gallery_localizations.dart';
77

8-
// BEGIN tabsDemo
8+
enum TabsDemoType {
9+
scrollable,
10+
nonScrollable,
11+
}
912

1013
class TabsDemo extends StatelessWidget {
14+
const TabsDemo({Key key, this.type}) : super(key: key);
15+
16+
final TabsDemoType type;
17+
18+
@override
19+
Widget build(BuildContext context) {
20+
Widget tabs;
21+
switch (type) {
22+
case TabsDemoType.scrollable:
23+
tabs = _TabsScrollableDemo();
24+
break;
25+
case TabsDemoType.nonScrollable:
26+
tabs = _TabsNonScrollableDemo();
27+
}
28+
return tabs;
29+
}
30+
}
31+
32+
// BEGIN tabsScrollableDemo
33+
34+
class _TabsScrollableDemo extends StatelessWidget {
1135
@override
1236
Widget build(BuildContext context) {
1337
List<String> tabs = [
@@ -17,14 +41,20 @@ class TabsDemo extends StatelessWidget {
1741
GalleryLocalizations.of(context).colorsBlue,
1842
GalleryLocalizations.of(context).colorsIndigo,
1943
GalleryLocalizations.of(context).colorsPurple,
44+
GalleryLocalizations.of(context).colorsRed,
45+
GalleryLocalizations.of(context).colorsOrange,
46+
GalleryLocalizations.of(context).colorsGreen,
47+
GalleryLocalizations.of(context).colorsBlue,
48+
GalleryLocalizations.of(context).colorsIndigo,
49+
GalleryLocalizations.of(context).colorsPurple,
2050
];
2151

2252
return DefaultTabController(
2353
length: tabs.length,
2454
child: Scaffold(
2555
appBar: AppBar(
2656
automaticallyImplyLeading: false,
27-
title: Text(GalleryLocalizations.of(context).demoTabsTitle),
57+
title: Text(GalleryLocalizations.of(context).demoTabsScrollingTitle),
2858
bottom: TabBar(
2959
isScrollable: true,
3060
tabs: [
@@ -46,3 +76,43 @@ class TabsDemo extends StatelessWidget {
4676
}
4777

4878
// END
79+
80+
// BEGIN tabsNonScrollableDemo
81+
82+
class _TabsNonScrollableDemo extends StatelessWidget {
83+
@override
84+
Widget build(BuildContext context) {
85+
List<String> tabs = [
86+
GalleryLocalizations.of(context).colorsRed,
87+
GalleryLocalizations.of(context).colorsOrange,
88+
GalleryLocalizations.of(context).colorsGreen,
89+
];
90+
91+
return DefaultTabController(
92+
length: tabs.length,
93+
child: Scaffold(
94+
appBar: AppBar(
95+
automaticallyImplyLeading: false,
96+
title:
97+
Text(GalleryLocalizations.of(context).demoTabsNonScrollingTitle),
98+
bottom: TabBar(
99+
isScrollable: false,
100+
tabs: [
101+
for (final tab in tabs) Tab(text: tab),
102+
],
103+
),
104+
),
105+
body: TabBarView(
106+
children: [
107+
for (final tab in tabs)
108+
Center(
109+
child: Text(tab),
110+
),
111+
],
112+
),
113+
),
114+
);
115+
}
116+
}
117+
118+
// END

gallery/gallery/lib/l10n/gallery_localizations.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2969,6 +2969,21 @@ class GalleryLocalizations {
29692969
desc: r'Description for tabs demo.');
29702970
}
29712971

2972+
String get demoTabsNonScrollingTitle {
2973+
return Intl.message('Non-scrolling',
2974+
locale: _localeName,
2975+
name: 'demoTabsNonScrollingTitle',
2976+
desc:
2977+
r'Title for tabs demo with a tab bar that doesn' "'" r't scroll.');
2978+
}
2979+
2980+
String get demoTabsScrollingTitle {
2981+
return Intl.message('Scrolling',
2982+
locale: _localeName,
2983+
name: 'demoTabsScrollingTitle',
2984+
desc: r'Title for tabs demo with a tab bar that scrolls.');
2985+
}
2986+
29722987
String get demoTabsSubtitle {
29732988
return Intl.message('Tabs with independently scrollable views',
29742989
locale: _localeName,

gallery/gallery/lib/l10n/intl_en_US.arb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,6 +1390,14 @@
13901390
"@demoTabsTitle": {
13911391
"description": "Title for tabs demo."
13921392
},
1393+
"demoTabsScrollingTitle": "Scrolling",
1394+
"@demoTabsScrollingTitle": {
1395+
"description": "Title for tabs demo with a tab bar that scrolls."
1396+
},
1397+
"demoTabsNonScrollingTitle": "Non-scrolling",
1398+
"@demoTabsNonScrollingTitle": {
1399+
"description": "Title for tabs demo with a tab bar that doesn't scroll."
1400+
},
13931401
"demoTabsSubtitle": "Tabs with independently scrollable views",
13941402
"@demoTabsSubtitle": {
13951403
"description": "Subtitle for tabs demo."

gallery/gallery/lib/l10n/intl_en_US.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,14 @@
13131313
name="demoTabsTitle"
13141314
description="Title for tabs demo."
13151315
>Tabs</string>
1316+
<string
1317+
name="demoTabsScrollingTitle"
1318+
description="Title for tabs demo with a tab bar that scrolls."
1319+
>Scrolling</string>
1320+
<string
1321+
name="demoTabsNonScrollingTitle"
1322+
description="Title for tabs demo with a tab bar that doesn&apos;t scroll."
1323+
>Non-scrolling</string>
13161324
<string
13171325
name="demoTabsSubtitle"
13181326
description="Subtitle for tabs demo."

gallery/gallery/lib/l10n/messages_en_US.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,10 @@ class MessageLookup extends MessageLookupByLibrary {
775775
"demoSnackbarsTitle": MessageLookupByLibrary.simpleMessage("Snackbars"),
776776
"demoTabsDescription": MessageLookupByLibrary.simpleMessage(
777777
"Tabs organize content across different screens, data sets, and other interactions."),
778+
"demoTabsNonScrollingTitle":
779+
MessageLookupByLibrary.simpleMessage("Non-scrolling"),
780+
"demoTabsScrollingTitle":
781+
MessageLookupByLibrary.simpleMessage("Scrolling"),
778782
"demoTabsSubtitle": MessageLookupByLibrary.simpleMessage(
779783
"Tabs with independently scrollable views"),
780784
"demoTabsTitle": MessageLookupByLibrary.simpleMessage("Tabs"),

0 commit comments

Comments
 (0)