From f716c0c58a6eed652f5c539db135d6f3ab12e6cd Mon Sep 17 00:00:00 2001 From: Moshe Dicker Date: Sun, 25 Feb 2024 15:24:08 -0500 Subject: [PATCH 1/6] add draggable_scrollable_controller --- .../src/draggable_scrollable_controller.dart | 31 ++++ packages/flutter_hooks/lib/src/hooks.dart | 2 + ..._draggable_scrollable_controller_test.dart | 134 ++++++++++++++++++ 3 files changed, 167 insertions(+) create mode 100644 packages/flutter_hooks/lib/src/draggable_scrollable_controller.dart create mode 100644 packages/flutter_hooks/test/use_draggable_scrollable_controller_test.dart diff --git a/packages/flutter_hooks/lib/src/draggable_scrollable_controller.dart b/packages/flutter_hooks/lib/src/draggable_scrollable_controller.dart new file mode 100644 index 00000000..2a0f1269 --- /dev/null +++ b/packages/flutter_hooks/lib/src/draggable_scrollable_controller.dart @@ -0,0 +1,31 @@ +part of 'hooks.dart'; + +/// Creates a [DraggableScrollableController] that will be disposed automatically. +/// +/// See also: +/// - [DraggableScrollableController] +DraggableScrollableController useDraggableScrollableController( + {List? keys}) { + return use(_DraggableScrollableControllerHook(keys: keys)); +} + +class _DraggableScrollableControllerHook + extends Hook { + const _DraggableScrollableControllerHook({List? keys}) + : super(keys: keys); + + @override + HookState> + createState() => _DraggableScrollableControllerHookState(); +} + +class _DraggableScrollableControllerHookState extends HookState< + DraggableScrollableController, _DraggableScrollableControllerHook> { + final controller = DraggableScrollableController(); + + @override + String get debugLabel => 'useDraggableScrollableController'; + + @override + DraggableScrollableController build(BuildContext context) => controller; +} diff --git a/packages/flutter_hooks/lib/src/hooks.dart b/packages/flutter_hooks/lib/src/hooks.dart index 7b6cfbfb..275d1b60 100644 --- a/packages/flutter_hooks/lib/src/hooks.dart +++ b/packages/flutter_hooks/lib/src/hooks.dart @@ -4,6 +4,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart' show Brightness, + DraggableScrollableController, ExpansionTileController, MaterialState, MaterialStatesController, @@ -16,6 +17,7 @@ import 'framework.dart'; part 'animation.dart'; part 'async.dart'; +part 'draggable_scrollable_controller.dart'; part 'expansion_tile_controller.dart'; part 'focus_node.dart'; part 'focus_scope_node.dart'; diff --git a/packages/flutter_hooks/test/use_draggable_scrollable_controller_test.dart b/packages/flutter_hooks/test/use_draggable_scrollable_controller_test.dart new file mode 100644 index 00000000..57729b8e --- /dev/null +++ b/packages/flutter_hooks/test/use_draggable_scrollable_controller_test.dart @@ -0,0 +1,134 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_hooks/src/framework.dart'; +import 'package:flutter_hooks/src/hooks.dart'; + +import 'mock.dart'; + +void main() { + testWidgets('debugFillProperties', (tester) async { + await tester.pumpWidget( + HookBuilder(builder: (context) { + useDraggableScrollableController(); + return const SizedBox(); + }), + ); + + await tester.pump(); + + final element = tester.element(find.byType(HookBuilder)); + + expect( + element + .toDiagnosticsNode(style: DiagnosticsTreeStyle.offstage) + .toStringDeep(), + equalsIgnoringHashCodes('HookBuilder\n' + ' │ useDraggableScrollableController: Instance of\n' + " │ 'DraggableScrollableController'\n" + ' └SizedBox(renderObject: RenderConstrainedBox#00000)\n'), + ); + }); + + group('useDraggableScrollableController', () { + testWidgets( + 'controller functions correctly and initial values matches with real constructor', + (tester) async { + late DraggableScrollableController controller; + final controller2 = DraggableScrollableController(); + + await tester.pumpWidget(MaterialApp( + home: Scaffold( + body: HookBuilder(builder: (context) { + return Column( + children: [ + ElevatedButton( + onPressed: () { + showBottomSheet( + context: context, + builder: (context) { + // Using a builder here to ensure that the controller is + // disposed when the sheet is closed. + return HookBuilder(builder: (context) { + controller = useDraggableScrollableController(); + return DraggableScrollableSheet( + controller: controller, + builder: (context, scrollController) { + return ListView.builder( + controller: scrollController, + itemCount: 100, + itemBuilder: (context, index) { + return ListTile( + title: Text('Item $index on Sheet 1'), + ); + }, + ); + }, + ); + }); + }); + }, + child: Text("Open Sheet 1")), + ElevatedButton( + onPressed: () { + showBottomSheet( + context: context, + builder: (context) { + return DraggableScrollableSheet( + controller: controller2, + builder: (context, scrollController) { + return ListView.builder( + controller: scrollController, + itemCount: 100, + itemBuilder: (context, index) { + return ListTile( + title: Text('Item $index on Sheet 2'), + ); + }, + ); + }, + ); + }); + }, + child: Text("Open Sheet 2")) + ], + ); + }), + ), + )); + + // Open Sheet 1 and get the initial values + await tester.tap(find.text('Open Sheet 1')); + await tester.pumpAndSettle(); + final controllerPixels = controller.pixels; + final controllerSize = controller.size; + final controllerIsAttached = controller.isAttached; + // Close Sheet 1 by dragging it down + await tester.fling( + find.byType(DraggableScrollableSheet), const Offset(0, 500), 300); + await tester.pumpAndSettle(); + + // Open Sheet 2 and get the initial values + await tester.tap(find.text('Open Sheet 2')); + await tester.pumpAndSettle(); + final controller2Pixels = controller2.pixels; + final controller2Size = controller2.size; + final controller2IsAttached = controller2.isAttached; + // Close Sheet 2 by dragging it down + await tester.fling( + find.byType(DraggableScrollableSheet), const Offset(0, 500), 300); + await tester.pumpAndSettle(); + + // Compare the initial values of the two controllers + expect(controllerPixels, controller2Pixels); + expect(controllerSize, controller2Size); + expect(controllerIsAttached, controller2IsAttached); + + // Open Sheet 1 again and use the controller to scroll + await tester.tap(find.text('Open Sheet 1')); + await tester.pumpAndSettle(); + const targetSize = 1.0; + controller.jumpTo(targetSize); + expect(targetSize, controller.size); + }); + }); +} From 10d35cbdbb83cbe1ac9f1061c10ec390edc94f7f Mon Sep 17 00:00:00 2001 From: Moshe Dicker Date: Mon, 26 Feb 2024 08:56:03 -0500 Subject: [PATCH 2/6] add dispose to draggable_scrollable_controller --- .../flutter_hooks/lib/src/draggable_scrollable_controller.dart | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/flutter_hooks/lib/src/draggable_scrollable_controller.dart b/packages/flutter_hooks/lib/src/draggable_scrollable_controller.dart index 2a0f1269..97dcb41c 100644 --- a/packages/flutter_hooks/lib/src/draggable_scrollable_controller.dart +++ b/packages/flutter_hooks/lib/src/draggable_scrollable_controller.dart @@ -28,4 +28,7 @@ class _DraggableScrollableControllerHookState extends HookState< @override DraggableScrollableController build(BuildContext context) => controller; + + @override + void dispose() => controller.dispose(); } From f4f8d62dd5aac93821732a0d7ac23c7454b84479 Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Wed, 28 Feb 2024 12:20:03 +0100 Subject: [PATCH 3/6] Apply suggestions from code review --- .../flutter_hooks/lib/src/draggable_scrollable_controller.dart | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/flutter_hooks/lib/src/draggable_scrollable_controller.dart b/packages/flutter_hooks/lib/src/draggable_scrollable_controller.dart index 97dcb41c..9885ab4c 100644 --- a/packages/flutter_hooks/lib/src/draggable_scrollable_controller.dart +++ b/packages/flutter_hooks/lib/src/draggable_scrollable_controller.dart @@ -11,8 +11,7 @@ DraggableScrollableController useDraggableScrollableController( class _DraggableScrollableControllerHook extends Hook { - const _DraggableScrollableControllerHook({List? keys}) - : super(keys: keys); + const _DraggableScrollableControllerHook({super.keys}); @override HookState> From 9e3537f8b0ec944fd39ed901946ad7f14a7a230a Mon Sep 17 00:00:00 2001 From: Moshe Dicker <75931499+dickermoshe@users.noreply.github.com> Date: Wed, 28 Feb 2024 09:03:35 -0500 Subject: [PATCH 4/6] Update packages/flutter_hooks/lib/src/draggable_scrollable_controller.dart Co-authored-by: Remi Rousselet --- .../flutter_hooks/lib/src/draggable_scrollable_controller.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/flutter_hooks/lib/src/draggable_scrollable_controller.dart b/packages/flutter_hooks/lib/src/draggable_scrollable_controller.dart index 9885ab4c..2ad2b621 100644 --- a/packages/flutter_hooks/lib/src/draggable_scrollable_controller.dart +++ b/packages/flutter_hooks/lib/src/draggable_scrollable_controller.dart @@ -5,7 +5,7 @@ part of 'hooks.dart'; /// See also: /// - [DraggableScrollableController] DraggableScrollableController useDraggableScrollableController( - {List? keys}) { + {List? keys,}) { return use(_DraggableScrollableControllerHook(keys: keys)); } From 1c16d3e1126e0c38bfa87817b9ebdc8ca53fa3b4 Mon Sep 17 00:00:00 2001 From: Moshe Dicker Date: Wed, 28 Feb 2024 09:07:05 -0500 Subject: [PATCH 5/6] update readme & changelog --- README.md | 51 +++++++++++++++-------------- packages/flutter_hooks/CHANGELOG.md | 4 +++ 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 6fb701fd..2bfe4b4a 100644 --- a/README.md +++ b/README.md @@ -310,12 +310,12 @@ They will take care of creating/updating/disposing an object. #### dart:async related hooks: -| Name | Description | -| ---------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- | -| [useStream](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useStream.html) | Subscribes to a `Stream` and returns its current state as an `AsyncSnapshot`. | -| [useStreamController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useStreamController.html) | Creates a `StreamController` which will automatically be disposed. | -| [useOnStreamChange](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useOnStreamChange.html) | Subscribes to a `Stream`, registers handlers, and returns the `StreamSubscription`. -| [useFuture](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useFuture.html) | Subscribes to a `Future` and returns its current state as an `AsyncSnapshot`. | +| Name | Description | +| ---------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- | +| [useStream](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useStream.html) | Subscribes to a `Stream` and returns its current state as an `AsyncSnapshot`. | +| [useStreamController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useStreamController.html) | Creates a `StreamController` which will automatically be disposed. | +| [useOnStreamChange](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useOnStreamChange.html) | Subscribes to a `Stream`, registers handlers, and returns the `StreamSubscription`. | +| [useFuture](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useFuture.html) | Subscribes to a `Future` and returns its current state as an `AsyncSnapshot`. | #### Animation related hooks: @@ -338,25 +338,26 @@ They will take care of creating/updating/disposing an object. A series of hooks with no particular theme. -| Name | Description | -| ------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------- | -| [useReducer](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useReducer.html) | An alternative to `useState` for more complex states. | -| [usePrevious](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/usePrevious.html) | Returns the previous argument called to [usePrevious]. | -| [useTextEditingController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useTextEditingController-constant.html) | Creates a `TextEditingController`. | -| [useFocusNode](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useFocusNode.html) | Creates a `FocusNode`. | -| [useTabController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useTabController.html) | Creates and disposes a `TabController`. | -| [useScrollController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useScrollController.html) | Creates and disposes a `ScrollController`. | -| [usePageController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/usePageController.html) | Creates and disposes a `PageController`. | -| [useAppLifecycleState](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useAppLifecycleState.html) | Returns the current `AppLifecycleState` and rebuilds the widget on change. | -| [useOnAppLifecycleStateChange](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useOnAppLifecycleStateChange.html) | Listens to `AppLifecycleState` changes and triggers a callback on change. | -| [useTransformationController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useTransformationController.html) | Creates and disposes a `TransformationController`. | -| [useIsMounted](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useIsMounted.html) | An equivalent to `State.mounted` for hooks. | -| [useAutomaticKeepAlive](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useAutomaticKeepAlive.html) | An equivalent to the `AutomaticKeepAlive` widget for hooks. | -| [useOnPlatformBrightnessChange](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useOnPlatformBrightnessChange.html) | Listens to platform `Brightness` changes and triggers a callback on change.| -| [useSearchController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useSearchController.html) | Creates and disposes a `SearchController`. | -| [useMaterialStatesController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useMaterialStatesController.html) | Creates and disposes a `MaterialStatesController`. | -| [useExpansionTileController](https://api.flutter.dev/flutter/material/ExpansionTileController-class.html) | Creates a `ExpansionTileController`. | -| [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 | +| Name | Description | +| ------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------- | +| [useReducer](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useReducer.html) | An alternative to `useState` for more complex states. | +| [usePrevious](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/usePrevious.html) | Returns the previous argument called to [usePrevious]. | +| [useTextEditingController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useTextEditingController-constant.html) | Creates a `TextEditingController`. | +| [useFocusNode](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useFocusNode.html) | Creates a `FocusNode`. | +| [useTabController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useTabController.html) | Creates and disposes a `TabController`. | +| [useScrollController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useScrollController.html) | Creates and disposes a `ScrollController`. | +| [usePageController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/usePageController.html) | Creates and disposes a `PageController`. | +| [useAppLifecycleState](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useAppLifecycleState.html) | Returns the current `AppLifecycleState` and rebuilds the widget on change. | +| [useOnAppLifecycleStateChange](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useOnAppLifecycleStateChange.html) | Listens to `AppLifecycleState` changes and triggers a callback on change. | +| [useTransformationController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useTransformationController.html) | Creates and disposes a `TransformationController`. | +| [useIsMounted](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useIsMounted.html) | An equivalent to `State.mounted` for hooks. | +| [useAutomaticKeepAlive](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useAutomaticKeepAlive.html) | An equivalent to the `AutomaticKeepAlive` widget for hooks. | +| [useOnPlatformBrightnessChange](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useOnPlatformBrightnessChange.html) | Listens to platform `Brightness` changes and triggers a callback on change. | +| [useSearchController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useSearchController.html) | Creates and disposes a `SearchController`. | +| [useMaterialStatesController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useMaterialStatesController.html) | Creates and disposes a `MaterialStatesController`. | +| [useExpansionTileController](https://api.flutter.dev/flutter/material/ExpansionTileController-class.html) | Creates a `ExpansionTileController`. | +| [useDraggableScrollableController](https://api.flutter.dev/flutter/widgets/DraggableScrollableController-class.html) | Creates a `DraggableScrollableController`. | +| [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 | ## Contributions diff --git a/packages/flutter_hooks/CHANGELOG.md b/packages/flutter_hooks/CHANGELOG.md index 3f29f42b..6992b3cf 100644 --- a/packages/flutter_hooks/CHANGELOG.md +++ b/packages/flutter_hooks/CHANGELOG.md @@ -1,3 +1,7 @@ +## Unreleased patch + +- Added `useDraggableScrollableController` + ## 0.20.5 - 2024-02-05 - Deprecate the `useIsMounted` hook as you should use `BuildContext.mounted` instead if you're on Flutter 3.7.0 or greater From d9cd970ef1714e7329c8c559ecd28c5fbc2ff467 Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Mon, 8 Jul 2024 07:43:56 +0200 Subject: [PATCH 6/6] Format --- README.md | 41 +++++++++---------- packages/flutter_hooks/CHANGELOG.md | 3 +- .../src/draggable_scrollable_controller.dart | 5 ++- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 03c170e7..602865d0 100644 --- a/README.md +++ b/README.md @@ -338,27 +338,26 @@ They will take care of creating/updating/disposing an object. A series of hooks with no particular theme. - -| Name | Description | -| ------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------- | -| [useReducer](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useReducer.html) | An alternative to `useState` for more complex states. | -| [usePrevious](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/usePrevious.html) | Returns the previous argument called to [usePrevious]. | -| [useTextEditingController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useTextEditingController-constant.html) | Creates a `TextEditingController`. | -| [useFocusNode](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useFocusNode.html) | Creates a `FocusNode`. | -| [useTabController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useTabController.html) | Creates and disposes a `TabController`. | -| [useScrollController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useScrollController.html) | Creates and disposes a `ScrollController`. | -| [usePageController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/usePageController.html) | Creates and disposes a `PageController`. | -| [useAppLifecycleState](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useAppLifecycleState.html) | Returns the current `AppLifecycleState` and rebuilds the widget on change. | -| [useOnAppLifecycleStateChange](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useOnAppLifecycleStateChange.html) | Listens to `AppLifecycleState` changes and triggers a callback on change. | -| [useTransformationController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useTransformationController.html) | Creates and disposes a `TransformationController`. | -| [useIsMounted](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useIsMounted.html) | An equivalent to `State.mounted` for hooks. | -| [useAutomaticKeepAlive](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useAutomaticKeepAlive.html) | An equivalent to the `AutomaticKeepAlive` widget for hooks. | -| [useOnPlatformBrightnessChange](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useOnPlatformBrightnessChange.html) | Listens to platform `Brightness` changes and triggers a callback on change.| -| [useSearchController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useSearchController.html) | Creates and disposes a `SearchController`. | -| [useWidgetStatesController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useWidgetStatesController.html) | Creates and disposes a `WidgetStatesController`. | -| [useExpansionTileController](https://api.flutter.dev/flutter/material/ExpansionTileController-class.html) | Creates a `ExpansionTileController`. | -| [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 | -| [useDraggableScrollableController](https://api.flutter.dev/flutter/widgets/DraggableScrollableController-class.html) | Creates a `DraggableScrollableController`. +| Name | Description | +| ------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------- | +| [useReducer](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useReducer.html) | An alternative to `useState` for more complex states. | +| [usePrevious](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/usePrevious.html) | Returns the previous argument called to [usePrevious]. | +| [useTextEditingController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useTextEditingController-constant.html) | Creates a `TextEditingController`. | +| [useFocusNode](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useFocusNode.html) | Creates a `FocusNode`. | +| [useTabController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useTabController.html) | Creates and disposes a `TabController`. | +| [useScrollController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useScrollController.html) | Creates and disposes a `ScrollController`. | +| [usePageController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/usePageController.html) | Creates and disposes a `PageController`. | +| [useAppLifecycleState](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useAppLifecycleState.html) | Returns the current `AppLifecycleState` and rebuilds the widget on change. | +| [useOnAppLifecycleStateChange](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useOnAppLifecycleStateChange.html) | Listens to `AppLifecycleState` changes and triggers a callback on change. | +| [useTransformationController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useTransformationController.html) | Creates and disposes a `TransformationController`. | +| [useIsMounted](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useIsMounted.html) | An equivalent to `State.mounted` for hooks. | +| [useAutomaticKeepAlive](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useAutomaticKeepAlive.html) | An equivalent to the `AutomaticKeepAlive` widget for hooks. | +| [useOnPlatformBrightnessChange](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useOnPlatformBrightnessChange.html) | Listens to platform `Brightness` changes and triggers a callback on change. | +| [useSearchController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useSearchController.html) | Creates and disposes a `SearchController`. | +| [useWidgetStatesController](https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useWidgetStatesController.html) | Creates and disposes a `WidgetStatesController`. | +| [useExpansionTileController](https://api.flutter.dev/flutter/material/ExpansionTileController-class.html) | Creates a `ExpansionTileController`. | +| [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 | +| [useDraggableScrollableController](https://api.flutter.dev/flutter/widgets/DraggableScrollableController-class.html) | Creates a `DraggableScrollableController`. | ## Contributions diff --git a/packages/flutter_hooks/CHANGELOG.md b/packages/flutter_hooks/CHANGELOG.md index b7ca9f3c..47efce35 100644 --- a/packages/flutter_hooks/CHANGELOG.md +++ b/packages/flutter_hooks/CHANGELOG.md @@ -1,7 +1,6 @@ - ## Unreleased patch -- Added `useDraggableScrollableController` +- Added `useDraggableScrollableController` (@thanks to @dickermoshe) ## 0.21.1-pre.0 diff --git a/packages/flutter_hooks/lib/src/draggable_scrollable_controller.dart b/packages/flutter_hooks/lib/src/draggable_scrollable_controller.dart index 2ad2b621..621a3392 100644 --- a/packages/flutter_hooks/lib/src/draggable_scrollable_controller.dart +++ b/packages/flutter_hooks/lib/src/draggable_scrollable_controller.dart @@ -4,8 +4,9 @@ part of 'hooks.dart'; /// /// See also: /// - [DraggableScrollableController] -DraggableScrollableController useDraggableScrollableController( - {List? keys,}) { +DraggableScrollableController useDraggableScrollableController({ + List? keys, +}) { return use(_DraggableScrollableControllerHook(keys: keys)); }