@@ -30,6 +30,12 @@ class ThemedTabView extends StatefulWidget {
3030 /// If the previous position is not available, it will default to the first tab.
3131 final bool persistTabPosition;
3232
33+ /// [initialPosition] is
34+ final int initialPosition;
35+
36+ /// [onTabIndex]
37+ final Function (int tabIndex)? onTabIndex;
38+
3339 /// [ThemedTabView] is a tab for the [TabBar] widget
3440 ///
3541 /// Be careful!
@@ -45,6 +51,8 @@ class ThemedTabView extends StatefulWidget {
4551 this .separatorPadding = const EdgeInsets .only (top: 10 ),
4652 this .showArrows = false ,
4753 this .persistTabPosition = true ,
54+ this .initialPosition = 0 ,
55+ this .onTabIndex,
4856 });
4957
5058 @override
@@ -61,10 +69,19 @@ class _ThemedTabViewState extends State<ThemedTabView> with TickerProviderStateM
6169 super .initState ();
6270
6371 _tabController = TabController (
72+ initialIndex: widget.initialPosition,
6473 length: widget.tabs.length,
6574 vsync: this ,
6675 animationDuration: widget.animationDuration,
6776 );
77+ if (widget.onTabIndex != null ) {
78+ _tabController.addListener (() {
79+ if (_tabController.indexIsChanging) {
80+ widget.onTabIndex !(_tabController.index);
81+ debugPrint ("tab change: ${_tabController .index }" );
82+ }
83+ });
84+ }
6885 }
6986
7087 @override
0 commit comments