Skip to content

Commit e802dd3

Browse files
authored
Merge pull request #473 from rrousselGit/lints
useExpansibleController
2 parents e8215f0 + 303ae67 commit e802dd3

10 files changed

+88
-55
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,10 @@ A series of hooks with no particular theme.
355355
| [useOnPlatformBrightnessChange](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useOnPlatformBrightnessChange.html) | Listens to platform `Brightness` changes and triggers a callback on change. |
356356
| [useSearchController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useSearchController.html) | Creates and disposes a `SearchController`. |
357357
| [useWidgetStatesController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useWidgetStatesController.html) | Creates and disposes a `WidgetStatesController`. |
358-
| [useExpansionTileController](https://api.flutter.dev/flutter/material/ExpansionTileController-class.html) | Creates a `ExpansionTileController`. |
358+
| [useExpansibleController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useExpansibleController.html) | Creates a `ExpansibleController`. |
359359
| [useDebounced](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useDebounced.html) | Returns a debounced version of the provided value, triggering widget updates accordingly after a specified timeout duration |
360360
| [useDraggableScrollableController](https://api.flutter.dev/flutter/widgets/DraggableScrollableController-class.html) | Creates a `DraggableScrollableController`. |
361-
| [useCarouselController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useCarouselController.html) | Creates and disposes a **`CarouselController`**. |
361+
| [useCarouselController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useCarouselController.html) | Creates and disposes a **`CarouselController`**. |
362362
| [useTreeSliverController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useTreeSliverController.html) | Creates a `TreeSliverController`. |
363363
| [useOverlayPortalController](https://api.flutter.dev/flutter/widgets/OverlayPortalController-class.html) | Creates and manages an `OverlayPortalController` for controlling the visibility of overlay content. The controller will be automatically disposed when no longer needed. |
364364

packages/flutter_hooks/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Unreleased patch
2+
3+
Deprecated `useExpansionTileController` in favor of `useExpansibleController`.
4+
15
## 0.21.2 - 2025-02-23
26

37
- Add `useCarouselController` (thanks to @riscait)
Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,37 @@
11
part of 'hooks.dart';
22

3+
/// Creates a [ExpansibleController] that will be disposed automatically.
4+
///
5+
/// See also:
6+
/// - [ExpansibleController]
7+
ExpansibleController useExpansibleController({List<Object?>? keys}) {
8+
return use(_ExpansibleControllerHook(keys: keys));
9+
}
10+
311
/// Creates a [ExpansionTileController] that will be disposed automatically.
412
///
513
/// See also:
614
/// - [ExpansionTileController]
15+
@Deprecated('Use `useExpansibleController` instead.')
716
ExpansionTileController useExpansionTileController({List<Object?>? keys}) {
8-
return use(_ExpansionTileControllerHook(keys: keys));
17+
return use(_ExpansibleControllerHook(keys: keys));
918
}
1019

11-
class _ExpansionTileControllerHook extends Hook<ExpansionTileController> {
12-
const _ExpansionTileControllerHook({List<Object?>? keys}) : super(keys: keys);
20+
class _ExpansibleControllerHook extends Hook<ExpansibleController> {
21+
const _ExpansibleControllerHook({List<Object?>? keys}) : super(keys: keys);
1322

1423
@override
15-
HookState<ExpansionTileController, Hook<ExpansionTileController>>
16-
createState() => _ExpansionTileControllerHookState();
24+
HookState<ExpansibleController, Hook<ExpansibleController>> createState() =>
25+
_ExpansibleControllerHookState();
1726
}
1827

19-
class _ExpansionTileControllerHookState
20-
extends HookState<ExpansionTileController, _ExpansionTileControllerHook> {
21-
final controller = ExpansionTileController();
28+
class _ExpansibleControllerHookState
29+
extends HookState<ExpansibleController, _ExpansibleControllerHook> {
30+
final controller = ExpansibleController();
2231

2332
@override
24-
String get debugLabel => 'useExpansionTileController';
33+
String get debugLabel => 'useExpansibleController';
2534

2635
@override
27-
ExpansionTileController build(BuildContext context) => controller;
36+
ExpansibleController build(BuildContext context) => controller;
2837
}

packages/flutter_hooks/lib/src/hooks.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:flutter/material.dart'
66
Brightness,
77
CarouselController,
88
DraggableScrollableController,
9+
// ignore: deprecated_member_use
910
ExpansionTileController,
1011
SearchController,
1112
TabController,

packages/flutter_hooks/lib/src/misc.dart

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
part of 'hooks.dart';
22

33
/// A store of mutable state that allows mutations by dispatching actions.
4-
abstract class Store<State, Action> {
4+
abstract class Store<StateT, ActionT> {
55
/// The current state.
66
///
77
/// This value may change after a call to [dispatch].
8-
State get state;
8+
StateT get state;
99

1010
/// Dispatches an action.
1111
///
1212
/// Actions are dispatched synchronously.
1313
/// It is impossible to try to dispatch actions during `build`.
14-
void dispatch(Action action);
14+
void dispatch(ActionT action);
1515
}
1616

1717
/// Composes an [Action] and a [State] to create a new [State].
@@ -33,10 +33,10 @@ typedef Reducer<State, Action> = State Function(State state, Action action);
3333
/// See also:
3434
/// * [Reducer]
3535
/// * [Store]
36-
Store<State, Action> useReducer<State, Action>(
37-
Reducer<State, Action> reducer, {
38-
required State initialState,
39-
required Action initialAction,
36+
Store<StateT, ActionT> useReducer<StateT, ActionT>(
37+
Reducer<StateT, ActionT> reducer, {
38+
required StateT initialState,
39+
required ActionT initialAction,
4040
}) {
4141
return use(
4242
_ReducerHook(
@@ -47,27 +47,27 @@ Store<State, Action> useReducer<State, Action>(
4747
);
4848
}
4949

50-
class _ReducerHook<State, Action> extends Hook<Store<State, Action>> {
50+
class _ReducerHook<StateT, ActionT> extends Hook<Store<StateT, ActionT>> {
5151
const _ReducerHook(
5252
this.reducer, {
5353
required this.initialState,
5454
required this.initialAction,
5555
});
5656

57-
final Reducer<State, Action> reducer;
58-
final State initialState;
59-
final Action initialAction;
57+
final Reducer<StateT, ActionT> reducer;
58+
final StateT initialState;
59+
final ActionT initialAction;
6060

6161
@override
62-
_ReducerHookState<State, Action> createState() =>
63-
_ReducerHookState<State, Action>();
62+
_ReducerHookState<StateT, ActionT> createState() =>
63+
_ReducerHookState<StateT, ActionT>();
6464
}
6565

66-
class _ReducerHookState<State, Action>
67-
extends HookState<Store<State, Action>, _ReducerHook<State, Action>>
68-
implements Store<State, Action> {
66+
class _ReducerHookState<StateT, ActionT>
67+
extends HookState<Store<StateT, ActionT>, _ReducerHook<StateT, ActionT>>
68+
implements Store<StateT, ActionT> {
6969
@override
70-
late State state = hook.reducer(hook.initialState, hook.initialAction);
70+
late StateT state = hook.reducer(hook.initialState, hook.initialAction);
7171

7272
@override
7373
void initHook() {
@@ -77,7 +77,7 @@ class _ReducerHookState<State, Action>
7777
}
7878

7979
@override
80-
void dispatch(Action action) {
80+
void dispatch(ActionT action) {
8181
final newState = hook.reducer(state, action);
8282

8383
if (state != newState) {
@@ -86,7 +86,7 @@ class _ReducerHookState<State, Action>
8686
}
8787

8888
@override
89-
Store<State, Action> build(BuildContext context) {
89+
Store<StateT, ActionT> build(BuildContext context) {
9090
return this;
9191
}
9292

packages/flutter_hooks/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ version: 0.21.2
77

88
environment:
99
sdk: ">=2.17.0 <3.0.0"
10-
flutter: ">=3.21.0-13.0.pre.4"
10+
flutter: ">=3.32.0"
1111

1212
dependencies:
1313
flutter:

packages/flutter_hooks/test/use_animation_controller_test.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:async';
2+
13
import 'package:flutter/foundation.dart';
24
import 'package:flutter/scheduler.dart';
35
import 'package:flutter/widgets.dart';
@@ -26,9 +28,10 @@ void main() {
2628

2729
controller
2830
..duration = const Duration(seconds: 1)
29-
..reverseDuration = const Duration(seconds: 1)
30-
// check has a ticker
31-
..forward();
31+
..reverseDuration = const Duration(seconds: 1);
32+
33+
// check has a ticker
34+
unawaited(controller.forward());
3235

3336
// dispose
3437
await tester.pumpWidget(const SizedBox());

packages/flutter_hooks/test/use_expansion_tile_controller_test.dart renamed to packages/flutter_hooks/test/use_expansible_controller_test.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ void main() {
99
testWidgets('debugFillProperties', (tester) async {
1010
await tester.pumpWidget(
1111
HookBuilder(builder: (context) {
12-
useExpansionTileController();
12+
useExpansibleController();
1313
return const SizedBox();
1414
}),
1515
);
@@ -24,21 +24,21 @@ void main() {
2424
.toStringDeep(),
2525
equalsIgnoringHashCodes(
2626
'HookBuilder\n'
27-
" │ useExpansionTileController: Instance of 'ExpansionTileController'\n"
27+
" │ useExpansibleController: Instance of 'ExpansibleController'\n"
2828
' └SizedBox(renderObject: RenderConstrainedBox#00000)\n',
2929
),
3030
);
3131
});
3232

33-
group('useExpansionTileController', () {
33+
group('useExpansibleController', () {
3434
testWidgets('initial values matches with real constructor', (tester) async {
35-
late ExpansionTileController controller;
36-
final controller2 = ExpansionTileController();
35+
late ExpansibleController controller;
36+
final controller2 = ExpansibleController();
3737

3838
await tester.pumpWidget(MaterialApp(
3939
home: Scaffold(
4040
body: HookBuilder(builder: (context) {
41-
controller = useExpansionTileController();
41+
controller = useExpansibleController();
4242
return Column(
4343
children: [
4444
ExpansionTile(
@@ -54,16 +54,16 @@ void main() {
5454
}),
5555
),
5656
));
57-
expect(controller, isA<ExpansionTileController>());
57+
expect(controller, isA<ExpansibleController>());
5858
expect(controller.isExpanded, controller2.isExpanded);
5959
});
6060

6161
testWidgets('check expansion/collapse of tile', (tester) async {
62-
late ExpansionTileController controller;
62+
late ExpansibleController controller;
6363
await tester.pumpWidget(MaterialApp(
6464
home: Scaffold(
6565
body: HookBuilder(builder: (context) {
66-
controller = useExpansionTileController();
66+
controller = useExpansibleController();
6767
return ExpansionTile(
6868
controller: controller,
6969
title: const Text('Expansion Tile'),

packages/flutter_hooks/test/use_ticker_provider_test.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:async';
2+
13
import 'package:flutter/foundation.dart';
24
import 'package:flutter/widgets.dart';
35
import 'package:flutter_hooks/flutter_hooks.dart';
@@ -41,8 +43,10 @@ void main() {
4143
));
4244

4345
final animationController = AnimationController(
44-
vsync: provider, duration: const Duration(seconds: 1))
45-
..forward();
46+
vsync: provider,
47+
duration: const Duration(seconds: 1),
48+
);
49+
unawaited(animationController.forward());
4650

4751
expect(() => AnimationController(vsync: provider), throwsFlutterError);
4852

packages/flutter_hooks/test/use_transformation_controller_test.dart

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,27 @@ void main() {
2020
element
2121
.toDiagnosticsNode(style: DiagnosticsTreeStyle.offstage)
2222
.toStringDeep(),
23-
equalsIgnoringHashCodes(
24-
'HookBuilder\n'
25-
' │ useTransformationController:\n'
26-
' │ TransformationController#00000([0] 1.0,0.0,0.0,0.0\n'
27-
' │ [1] 0.0,1.0,0.0,0.0\n'
28-
' │ [2] 0.0,0.0,1.0,0.0\n'
29-
' │ [3] 0.0,0.0,0.0,1.0\n'
30-
' │ )\n'
31-
' └SizedBox(renderObject: RenderConstrainedBox#00000)\n',
23+
anyOf(
24+
equalsIgnoringHashCodes(
25+
'HookBuilder\n'
26+
' │ useTransformationController:\n'
27+
' │ TransformationController#00000([0] 1.0,0.0,0.0,0.0\n'
28+
' │ [1] 0.0,1.0,0.0,0.0\n'
29+
' │ [2] 0.0,0.0,1.0,0.0\n'
30+
' │ [3] 0.0,0.0,0.0,1.0\n'
31+
' │ )\n'
32+
' └SizedBox(renderObject: RenderConstrainedBox#00000)\n',
33+
),
34+
equalsIgnoringHashCodes(
35+
'HookBuilder\n'
36+
' │ useTransformationController:\n'
37+
' │ TransformationController#00000([0] [1.0,0.0,0.0,0.0]\n'
38+
' │ [1] [0.0,1.0,0.0,0.0]\n'
39+
' │ [2] [0.0,0.0,1.0,0.0]\n'
40+
' │ [3] [0.0,0.0,0.0,1.0]\n'
41+
' │ )\n'
42+
' └SizedBox(renderObject: RenderConstrainedBox#00000)\n',
43+
),
3244
),
3345
);
3446
});

0 commit comments

Comments
 (0)