Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork186
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 ourterms of service andprivacy 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?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
coderabbitaibot commentedJun 17, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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 withCodeRabbit:
SupportNeed help? Create a ticket on oursupport 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 butnot 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 wordCupertino 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 – missingflutter_test
import & unusedmock.dart
testWidgets
,equalsIgnoringHashCodes
, and other testing utilities live inpackage: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';
(Removemock.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 1to 7, the test file is missing the import forpackage:flutter_test/flutter_test.dart, which provides essential testingutilities like testWidgets and equalsIgnoringHashCodes. Add this import toenable the tests to compile. Also, remove the import of mock.dart since it isnot used anywhere in the file to avoid unused import lint warnings and reduceunnecessary internal API exposure.
Uh oh!
There was an error while loading.Please reload this page.
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