55import 'package:flutter/material.dart' ;
66import 'package:gallery/l10n/gallery_localizations.dart' ;
77
8- // BEGIN tabsDemo
8+ enum TabsDemoType {
9+ scrollable,
10+ nonScrollable,
11+ }
912
1013class 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
0 commit comments