-
-
Notifications
You must be signed in to change notification settings - Fork 186
Add useCupertinoTabController hook for automatic disposal of CupertinoTabController #475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
WalkthroughA new Flutter hook, Changes
Sequence Diagram(s)sequenceDiagram
participant Widget
participant HookBuilder
participant useCupertinoTabController
participant CupertinoTabController
Widget->>HookBuilder: Build widget tree
HookBuilder->>useCupertinoTabController: Invoke hook (with initialIndex)
useCupertinoTabController->>CupertinoTabController: Instantiate (if first build)
useCupertinoTabController-->>HookBuilder: Return controller instance
HookBuilder-->>Widget: Provide controller for use
Widget-->>CupertinoTabController: Use controller as needed
Assessment against linked issues
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (4)
packages/flutter_hooks/lib/src/hooks.dart (1)
3-4
: Minor style inconsistency in multi-line importThe previous multi-line
import 'package:flutter/material.dart'
statement keeps the URI and theshow
combinator on the same physical line (see lines 6-17). For consistency, consider collapsing lines 3-4 into one line or applying the same line-break pattern to both imports.packages/flutter_hooks/lib/src/cupertino_tab_controller.dart (2)
20-30
: Parameter not included inkeys
– check desire to recreate controller on param change
initialIndex
is forwarded to the hook state but not added to thekeys
list.
If a parent widget rebuilds with a differentinitialIndex
, the existingCupertinoTabController
will be reused instead of creating a fresh one. That is usually correct (developers can callcontroller.index = …
instead), but double-check that this matches the intended behaviour for your API.return use( _CupertinoTabControllerHook( initialIndex: initialIndex, - keys: keys, + keys: keys ?? <Object?>[initialIndex], ), );
35-43
: Missingsuper.dispose()
call is harmless but adds clarity
HookState.dispose
is currently a no-op, so omittingsuper.dispose()
is safe.
Calling it anyway improves forward-compatibility and mirrors patterns elsewhere in the codebase.@override void dispose() { controller.dispose(); + super.dispose(); }
packages/flutter_hooks/test/use_cupertino_tab_controller_test.dart (1)
33-34
: Typo in group description
useCupertinoCupertinoCupertinoTabController
has the word Cupertino repeated three times.-group('useCupertinoCupertinoCupertinoTabController', () { +group('useCupertinoTabController', () {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
packages/flutter_hooks/lib/src/cupertino_tab_controller.dart
(1 hunks)packages/flutter_hooks/lib/src/hooks.dart
(2 hunks)packages/flutter_hooks/test/use_cupertino_tab_controller_test.dart
(1 hunks)
import 'package:flutter/cupertino.dart'; | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter_hooks/src/framework.dart'; | ||
import 'package:flutter_hooks/src/hooks.dart'; | ||
|
||
import 'mock.dart'; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests fail to compile – missing flutter_test
import & unused mock.dart
testWidgets
, equalsIgnoringHashCodes
, and other testing utilities live in package:flutter_test/flutter_test.dart
, which is not imported.
mock.dart
is imported but never referenced, causing an “unused import” lint.
-import 'package:flutter/foundation.dart';
-import 'package:flutter_hooks/src/framework.dart';
-import 'package:flutter_hooks/src/hooks.dart';
-import 'mock.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:flutter_hooks/flutter_hooks.dart';
(Remove mock.dart
unless it is actually used.)
This change lets the suite compile and removes needless internal-API exposure.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
import 'package:flutter/cupertino.dart'; | |
import 'package:flutter/foundation.dart'; | |
import 'package:flutter_hooks/src/framework.dart'; | |
import 'package:flutter_hooks/src/hooks.dart'; | |
import 'mock.dart'; | |
import 'package:flutter/cupertino.dart'; | |
import 'package:flutter_test/flutter_test.dart'; | |
import 'package:flutter_hooks/flutter_hooks.dart'; |
🤖 Prompt for AI Agents
In packages/flutter_hooks/test/use_cupertino_tab_controller_test.dart at lines 1
to 7, the test file is missing the import for
package:flutter_test/flutter_test.dart, which provides essential testing
utilities like testWidgets and equalsIgnoringHashCodes. Add this import to
enable the tests to compile. Also, remove the import of mock.dart since it is
not used anywhere in the file to avoid unused import lint warnings and reduce
unnecessary internal API exposure.
Hi Remi 👋
Resolves #222
Introduce a new hook for managing the lifecycle of CupertinoTabController, ensuring it disposes automatically. Include tests to verify its functionality and correct behavior.
no towel required. 🪐
Summary by CodeRabbit
New Features
Tests