Skip to content

Commit f4f4461

Browse files
author
mromero
committed
update
1 parent fe8fde5 commit f4f4461

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## 7.4.4
4+
- Added `initialPosition` and `onTabIndex` in `ThemedTabView`
5+
36
## 7.4.3
47

58
- Added `ThemedTable2OnTapBehavior` enum to define the default behavior of onTap events on table cells.

lib/src/tabs/src/view.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)