Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 239c387

Browse files
authored
Merge pull request #446 from d-polikhranidi/patch-1
Add animationDuration property to useTabController hook
2 parents a203adf + 2dd4eba commit 239c387

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

packages/flutter_hooks/lib/src/hooks.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import 'package:flutter/material.dart'
77
CarouselController,
88
DraggableScrollableController,
99
ExpansionTileController,
10-
WidgetStatesController,
1110
SearchController,
1211
TabController,
13-
TreeSliverController,
14-
WidgetState;
12+
WidgetState,
13+
WidgetStatesController,
14+
kTabScrollDuration;
1515
import 'package:flutter/scheduler.dart';
1616
import 'package:flutter/widgets.dart';
1717

packages/flutter_hooks/lib/src/tab_controller.dart

+7-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ part of 'hooks.dart';
66
/// - [TabController]
77
TabController useTabController({
88
required int initialLength,
9+
Duration? animationDuration = kTabScrollDuration,
910
TickerProvider? vsync,
1011
int initialIndex = 0,
1112
List<Object?>? keys,
@@ -17,6 +18,7 @@ TabController useTabController({
1718
vsync: vsync,
1819
length: initialLength,
1920
initialIndex: initialIndex,
21+
animationDuration: animationDuration,
2022
keys: keys,
2123
),
2224
);
@@ -27,12 +29,14 @@ class _TabControllerHook extends Hook<TabController> {
2729
required this.length,
2830
required this.vsync,
2931
required this.initialIndex,
30-
List<Object?>? keys,
31-
}) : super(keys: keys);
32+
required this.animationDuration,
33+
super.keys,
34+
});
3235

3336
final int length;
3437
final TickerProvider vsync;
3538
final int initialIndex;
39+
final Duration? animationDuration;
3640

3741
@override
3842
HookState<TabController, Hook<TabController>> createState() =>
@@ -44,6 +48,7 @@ class _TabControllerHookState
4448
late final controller = TabController(
4549
length: hook.length,
4650
initialIndex: hook.initialIndex,
51+
animationDuration: hook.animationDuration,
4752
vsync: hook.vsync,
4853
);
4954

packages/flutter_hooks/test/use_tab_controller_test.dart

+19
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,25 @@ void main() {
138138
verifyNoMoreInteractions(vsync);
139139
ticker.dispose();
140140
});
141+
142+
testWidgets('initial animationDuration matches with real constructor',
143+
(tester) async {
144+
late TabController controller;
145+
late TabController controller2;
146+
147+
await tester.pumpWidget(
148+
HookBuilder(
149+
builder: (context) {
150+
final vsync = useSingleTickerProvider();
151+
controller = useTabController(initialLength: 4);
152+
controller2 = TabController(length: 4, vsync: vsync);
153+
return Container();
154+
},
155+
),
156+
);
157+
158+
expect(controller.animationDuration, controller2.animationDuration);
159+
});
141160
});
142161
}
143162

0 commit comments

Comments
 (0)