Skip to content

[Gallery] Add options to tabs demo #290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
271 changes: 268 additions & 3 deletions gallery/gallery/lib/codeviewer/code_segments.dart

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions gallery/gallery/lib/data/demos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -524,11 +524,18 @@ List<GalleryDemo> materialDemos(BuildContext context) {
subtitle: localizations.demoTabsSubtitle,
configurations: [
GalleryDemoConfiguration(
title: localizations.demoTabsTitle,
title: localizations.demoTabsScrollingTitle,
description: localizations.demoTabsDescription,
documentationUrl: '$_docsBaseUrl/material/TabBarView-class.html',
buildRoute: (context) => TabsDemo(),
code: CodeSegments.tabsDemo,
documentationUrl: '$_docsBaseUrl/material/TabBar-class.html',
buildRoute: (context) => TabsDemo(type: TabsDemoType.scrollable),
code: CodeSegments.tabsScrollableDemo,
),
GalleryDemoConfiguration(
title: localizations.demoTabsNonScrollingTitle,
description: localizations.demoTabsDescription,
documentationUrl: '$_docsBaseUrl/material/TabBar-class.html',
buildRoute: (context) => TabsDemo(type: TabsDemoType.nonScrollable),
code: CodeSegments.tabsNonScrollableDemo,
),
],
),
Expand Down
74 changes: 72 additions & 2 deletions gallery/gallery/lib/demos/material/tabs_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,33 @@
import 'package:flutter/material.dart';
import 'package:gallery/l10n/gallery_localizations.dart';

// BEGIN tabsDemo
enum TabsDemoType {
scrollable,
nonScrollable,
}

class TabsDemo extends StatelessWidget {
const TabsDemo({Key key, this.type}) : super(key: key);

final TabsDemoType type;

@override
Widget build(BuildContext context) {
Widget tabs;
switch (type) {
case TabsDemoType.scrollable:
tabs = _TabsScrollableDemo();
break;
case TabsDemoType.nonScrollable:
tabs = _TabsNonScrollableDemo();
}
return tabs;
}
}

// BEGIN tabsScrollableDemo

class _TabsScrollableDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
List<String> tabs = [
Expand All @@ -17,14 +41,20 @@ class TabsDemo extends StatelessWidget {
GalleryLocalizations.of(context).colorsBlue,
GalleryLocalizations.of(context).colorsIndigo,
GalleryLocalizations.of(context).colorsPurple,
GalleryLocalizations.of(context).colorsRed,
GalleryLocalizations.of(context).colorsOrange,
GalleryLocalizations.of(context).colorsGreen,
GalleryLocalizations.of(context).colorsBlue,
GalleryLocalizations.of(context).colorsIndigo,
GalleryLocalizations.of(context).colorsPurple,
];

return DefaultTabController(
length: tabs.length,
child: Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
title: Text(GalleryLocalizations.of(context).demoTabsTitle),
title: Text(GalleryLocalizations.of(context).demoTabsScrollingTitle),
bottom: TabBar(
isScrollable: true,
tabs: [
Expand All @@ -46,3 +76,43 @@ class TabsDemo extends StatelessWidget {
}

// END

// BEGIN tabsNonScrollableDemo

class _TabsNonScrollableDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
List<String> tabs = [
GalleryLocalizations.of(context).colorsRed,
GalleryLocalizations.of(context).colorsOrange,
GalleryLocalizations.of(context).colorsGreen,
];

return DefaultTabController(
length: tabs.length,
child: Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
title:
Text(GalleryLocalizations.of(context).demoTabsNonScrollingTitle),
bottom: TabBar(
isScrollable: false,
tabs: [
for (final tab in tabs) Tab(text: tab),
],
),
),
body: TabBarView(
children: [
for (final tab in tabs)
Center(
child: Text(tab),
),
],
),
),
);
}
}

// END
15 changes: 15 additions & 0 deletions gallery/gallery/lib/l10n/gallery_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2969,6 +2969,21 @@ class GalleryLocalizations {
desc: r'Description for tabs demo.');
}

String get demoTabsNonScrollingTitle {
return Intl.message('Non-scrolling',
locale: _localeName,
name: 'demoTabsNonScrollingTitle',
desc:
r'Title for tabs demo with a tab bar that doesn' "'" r't scroll.');
}

String get demoTabsScrollingTitle {
return Intl.message('Scrolling',
locale: _localeName,
name: 'demoTabsScrollingTitle',
desc: r'Title for tabs demo with a tab bar that scrolls.');
}

String get demoTabsSubtitle {
return Intl.message('Tabs with independently scrollable views',
locale: _localeName,
Expand Down
8 changes: 8 additions & 0 deletions gallery/gallery/lib/l10n/intl_en_US.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,14 @@
"@demoTabsTitle": {
"description": "Title for tabs demo."
},
"demoTabsScrollingTitle": "Scrolling",
"@demoTabsScrollingTitle": {
"description": "Title for tabs demo with a tab bar that scrolls."
},
"demoTabsNonScrollingTitle": "Non-scrolling",
"@demoTabsNonScrollingTitle": {
"description": "Title for tabs demo with a tab bar that doesn't scroll."
},
"demoTabsSubtitle": "Tabs with independently scrollable views",
"@demoTabsSubtitle": {
"description": "Subtitle for tabs demo."
Expand Down
8 changes: 8 additions & 0 deletions gallery/gallery/lib/l10n/intl_en_US.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,14 @@
name="demoTabsTitle"
description="Title for tabs demo."
>Tabs</string>
<string
name="demoTabsScrollingTitle"
description="Title for tabs demo with a tab bar that scrolls."
>Scrolling</string>
<string
name="demoTabsNonScrollingTitle"
description="Title for tabs demo with a tab bar that doesn&apos;t scroll."
>Non-scrolling</string>
<string
name="demoTabsSubtitle"
description="Subtitle for tabs demo."
Expand Down
4 changes: 4 additions & 0 deletions gallery/gallery/lib/l10n/messages_en_US.dart
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,10 @@ class MessageLookup extends MessageLookupByLibrary {
"demoSnackbarsTitle": MessageLookupByLibrary.simpleMessage("Snackbars"),
"demoTabsDescription": MessageLookupByLibrary.simpleMessage(
"Tabs organize content across different screens, data sets, and other interactions."),
"demoTabsNonScrollingTitle":
MessageLookupByLibrary.simpleMessage("Non-scrolling"),
"demoTabsScrollingTitle":
MessageLookupByLibrary.simpleMessage("Scrolling"),
"demoTabsSubtitle": MessageLookupByLibrary.simpleMessage(
"Tabs with independently scrollable views"),
"demoTabsTitle": MessageLookupByLibrary.simpleMessage("Tabs"),
Expand Down