1+ import 'package:flutter/gestures.dart' ;
12import 'package:flutter/rendering.dart' ;
23import 'package:flutter/material.dart' ;
34import 'package:flutter/widgets.dart' ;
@@ -16,8 +17,9 @@ class GFTabBar extends StatefulWidget {
1617 /// [TabController.length] .
1718 const GFTabBar ({
1819 Key key,
19- this .initialIndex = 0 ,
20+ // this.initialIndex = 0,
2021 @required this .length,
22+ this .isScrollable = false ,
2123 this .tabBarHeight,
2224 this .tabBarColor,
2325 this .indicatorColor,
@@ -34,13 +36,14 @@ class GFTabBar extends StatefulWidget {
3436 this .controller,
3537 this .shape,
3638 }) : assert (length != null && length >= 0 ),
37- assert (initialIndex != null &&
38- initialIndex >= 0 &&
39- (length == 0 || initialIndex < length)),
39+ assert (isScrollable != null ),
40+ // assert(initialIndex != null &&
41+ // initialIndex >= 0 &&
42+ // (length == 0 || initialIndex < length)),
4043 super (key: key);
4144
42- /// The initial index of the selected tab. Defaults to zero.
43- final int initialIndex;
45+ // /// The initial index of the selected tab. Defaults to zero.
46+ // final int initialIndex;
4447
4548 /// The total number of tabs. Typically greater than one. Must match [TabBar.tabs] 's and
4649 /// [TabBarView.children] 's length.
@@ -151,6 +154,13 @@ class GFTabBar extends StatefulWidget {
151154 /// and the length of the [TabBarView.children] list.
152155 final List <Widget > tabs;
153156
157+ /// Whether this tab bar can be scrolled horizontally.
158+ ///
159+ /// If [isScrollable] is true, then each tab is as wide as needed for its label
160+ /// and the entire [TabBar] is scrollable. Otherwise each tab gets an equal
161+ /// share of the available space.
162+ final bool isScrollable;
163+
154164 /// This widget's selection and animation state.
155165 ///
156166 /// If [TabController] is not provided, then the value of [DefaultTabController.of]
@@ -165,26 +175,36 @@ class GFTabBar extends StatefulWidget {
165175}
166176
167177class _GFTabBarState extends State <GFTabBar > {
178+ ScrollController _scrollController;
179+ DragStartBehavior dragStartBehavior = DragStartBehavior .start;
180+
168181 @override
169- Widget build (BuildContext context) => Container (
170- height: widget.tabBarHeight ?? MediaQuery .of (context).size.height * 0.1 ,
171- child: Material (
172- shape: widget.shape,
173- type: MaterialType .button,
174- color: widget.tabBarColor ?? GFColors .PRIMARY ,
175- child: TabBar (
176- controller: widget.controller,
177- labelColor: widget.labelColor,
178- unselectedLabelColor: widget.unselectedLabelColor,
179- labelStyle: widget.labelStyle,
180- unselectedLabelStyle: widget.unselectedLabelStyle,
181- indicatorColor: widget.indicatorColor,
182- indicatorSize: widget.indicatorSize,
183- indicator: widget.indicator,
184- indicatorPadding: widget.indicatorPadding,
185- indicatorWeight: widget.indicatorWeight,
186- tabs: widget.tabs,
182+ Widget build (BuildContext context) => SingleChildScrollView (
183+ dragStartBehavior: dragStartBehavior,
184+ scrollDirection: Axis .horizontal,
185+ controller: _scrollController,
186+ child: Container (
187+ width: MediaQuery .of (context).size.width,
188+ height: widget.tabBarHeight ?? MediaQuery .of (context).size.height * 0.1 ,
189+ child: Material (
190+ shape: widget.shape,
191+ type: MaterialType .button,
192+ color: widget.tabBarColor ?? GFColors .PRIMARY ,
193+ child: TabBar (
194+ isScrollable: widget.isScrollable,
195+ controller: widget.controller,
196+ labelColor: widget.labelColor,
197+ unselectedLabelColor: widget.unselectedLabelColor,
198+ labelStyle: widget.labelStyle,
199+ unselectedLabelStyle: widget.unselectedLabelStyle,
200+ indicatorColor: widget.indicatorColor,
201+ indicatorSize: widget.indicatorSize,
202+ indicator: widget.indicator,
203+ indicatorPadding: widget.indicatorPadding,
204+ indicatorWeight: widget.indicatorWeight,
205+ tabs: widget.tabs,
206+ ),
187207 ),
188208 ),
189- );
209+ );
190210}
0 commit comments