Skip to content

[FIX] Migrate deprecated Flutter APIs (PopScope, TextButton, Theme/TextTheme updates)#199

Open
ObaidAbdullah16 wants to merge 2 commits intoCCExtractor:mainfrom
ObaidAbdullah16:fix/flutter-analyze-deprecations
Open

[FIX] Migrate deprecated Flutter APIs (PopScope, TextButton, Theme/TextTheme updates)#199
ObaidAbdullah16 wants to merge 2 commits intoCCExtractor:mainfrom
ObaidAbdullah16:fix/flutter-analyze-deprecations

Conversation

@ObaidAbdullah16
Copy link
Copy Markdown

@ObaidAbdullah16 ObaidAbdullah16 commented Apr 4, 2026

Summary

This PR updates deprecated Flutter framework APIs to keep the project compatible with newer Flutter/Dart SDK versions and eliminate analyzer deprecation warnings.

What changed

  • Replaced deprecated/removed widgets and APIs:
    • FlatButtonTextButton
    • WillPopScopePopScope
    • ElevatedButton.styleFrom(primary: ...)backgroundColor: ...
    • textTheme.subtitle1textTheme.titleMedium
    • textTheme.buttontextTheme.labelLarge
  • Updated theme and Material API usage:
    • Removed deprecated toggleableActiveColor from app_theme.dart
    • Replaced colorScheme.background with colorScheme.surface where applicable
  • Updated color opacity usage:
    • withOpacity(...)withValues(alpha: ...)
  • Updated Stacked bottom-sheet response API:
    • SheetResponse(responseData: ...)SheetResponse(data: ...)
  • Removed deprecation ignore directives by applying proper API migrations
  • Tooling/tests:
    • Adjusted stacked_generator version and refreshed pubspec.lock
    • Updated Mockito mock generation annotations to current MockSpec<T>() usage

Testing

  • flutter analyze (no issues found)

Scope

  • 16 files changed
  • +608 / -385 lines

Fixes #185
Closes #177

Summary by CodeRabbit

  • Refactor

    • Modernized deprecated Flutter components and button styles across the UI.
    • Improved back-navigation handling for several views to make back presses more reliable.
    • Adjusted text and surface color usages and subtle shadow rendering for more consistent visuals.
    • Streamlined selection controls in bottom sheets for a clearer selection flow.
  • Chores

    • Updated development tooling and adjusted test mock generation settings.

- Replace FlatButton with TextButton in bottom_sheet_setup.dart and
  confirm_bottom_sheet_view.dart (removed in Flutter 3.x)
- Remove deprecated toggleableActiveColor from app_theme.dart
- Replace deprecated 'primary:' with 'backgroundColor:' across multiple files
- Replace deprecated textTheme.subtitle1 with titleMedium
- Downgrade stacked_generator from ^0.7.13 to ^0.7.8 to resolve
  test_api version conflict with Flutter 3.x SDK

Fixes CCExtractor#185, closes CCExtractor#177
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 4, 2026

📝 Walkthrough

Walkthrough

Removed deprecated APIs and modernized widgets: dropped toggleableActiveColor, replaced WillPopScope with PopScope, migrated deprecated button/theme APIs, adjusted BoxShadow alpha API, updated video controller URL usage, tweaked mocked generation options, and migrated FlatButton to TextButton with related payload naming change in a bottom sheet response.

Changes

Cohort / File(s) Summary
Theme & Color Updates
lib/theme/app_theme.dart, lib/ui/shared/shared_styles.dart
Removed toggleableActiveColor entries from themes; changed BoxShadow color calls from Colors.grey.withOpacity(0.5) to Colors.grey.withValues(alpha: 0.5).
Back-navigation Handling
lib/ui/views/Download/download_view.dart, lib/ui/views/disk_explorer/disk_explorer_view.dart
Replaced WillPopScope with PopScope (set canPop: false) and implemented onPopInvokedWithResult async handlers that call model.onBackPress() and conditionally Navigator.of(context).pop() with context.mounted checks.
TextTheme & Styling Updates
lib/ui/views/IRSSI/IRSSI_view.dart, lib/ui/widgets/dumb_widgets/document_type_card.dart
Replaced deprecated text styles: subtitle1titleMedium; buttonlabelLarge. Adjusted a card background from colorScheme.backgroundcolorScheme.surface.
ElevatedButton API Migration
lib/ui/views/login/login_view.dart, lib/ui/widgets/dumb_widgets/password_change_dialog_widget.dart, lib/ui/widgets/dumb_widgets/torrent_label_dialog.dart, lib/ui/widgets/smart_widgets/url_bottom_sheet/url_bottomsheet_view.dart
Replaced primary: with backgroundColor: in ElevatedButton.styleFrom(...) calls, preserving existing conditional color logic.
FlatButton → TextButton & BottomSheet Response
lib/ui/widgets/smart_widgets/bottom_sheets/bottom_sheet_setup.dart, lib/ui/widgets/smart_widgets/bottom_sheets/confirm_bottom_sheet/confirm_bottom_sheet_view.dart
Removed file-level deprecation ignore; replaced FlatButton with TextButton and applied TextButton.styleFrom(backgroundColor: ...). Changed SheetResponse payload field from responseData: to data: when confirmed.
Sort Bottom Sheet Restructure
lib/ui/widgets/smart_widgets/bottom_sheets/sort_bottom_sheet/sort_bottom_sheet_view.dart
Added explicit viewModelBuilder; centralized selection using RadioGroup<Sort> and simplified per-row Radio/tap handling (use InkWell, render missing labels as SizedBox.shrink()).
Media Player URL API
lib/ui/views/media_player/media_stream_viewmodel.dart
Switched video controller creation from VideoPlayerController.network(String) to VideoPlayerController.networkUrl(Uri.parse(...)).
Mockito Generation Options
test/helpers/test_helpers.dart, test/helpers/test_helpers.mocks.dart
Removed returnNullOnMissingStub: true from @GenerateMocks MockSpecs; adjusted formatting of a generated _FakeValueNotifier_0<T> private helper declaration.
Dependency Pinning
pubspec.yaml
Changed stacked_generator dev dependency from ^0.7.13 to ^0.7.8.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I hopped through code to clear the way,
Deprecated crumbs I swept away,
PopScope, TextButton, URIs anew,
Shadows softened with a gentler hue,
Tests and sheets now sing—hooray! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: migration of deprecated Flutter APIs including PopScope, TextButton, and Theme/TextTheme updates.
Linked Issues check ✅ Passed All coding requirements from issues #185 and #177 are addressed: toggleableActiveColor removed, ElevatedButton.primary→backgroundColor, textTheme migrations applied, FlatButton→TextButton, and colorScheme/opacity updates implemented.
Out of Scope Changes check ✅ Passed Changes are focused on API migrations with minor scope inclusions: stacked_generator version adjustment and mockito mock configuration updates are reasonable maintenance changes to support the deprecation fixes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a 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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
lib/ui/views/IRSSI/IRSSI_view.dart (1)

255-283: ⚠️ Potential issue | 🟡 Minor

Replace deprecated colorScheme.background with colorScheme.surface.

Line 282 uses Theme.of(context).colorScheme.background, which is deprecated in Flutter's Material 3. Replace it with colorScheme.surface as recommended in the Flutter breaking change documentation.

Suggested patch
-                                                          : Theme.of(context)
-                                                              .colorScheme
-                                                              .background,
+                                                          : Theme.of(context)
+                                                              .colorScheme
+                                                              .surface,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/ui/views/IRSSI/IRSSI_view.dart` around lines 255 - 283, In the Container
decoration inside the IRSSI view build (the block creating subtitle1 and
returning the Container), replace Theme.of(context).colorScheme.background with
Theme.of(context).colorScheme.surface to avoid the deprecated background role;
update any similar uses in that widget (e.g., where the Container's color is
set) to use colorScheme.surface so the UI follows Material 3 color roles (keep
the rest of the ternary for dark mode unchanged).
🧹 Nitpick comments (1)
test/helpers/test_helpers.dart (1)

69-75: Consider adding stubs or documenting expected stubbing pattern.

MockHistoryService is registered without any stubs. With returnNullOnMissingStub removed, any test calling methods on this mock without explicit stubs will throw MissingStubError.

This is fine if individual tests set up their own stubs, but inconsistent with getAndRegisterAuthenticationService (line 81) and getAndRegisterHttpIOClientMock (line 63) which pre-configure stubs.

Consider either:

  1. Adding common stubs here for frequently-used methods, or
  2. Documenting that tests must stub methods before use
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/helpers/test_helpers.dart` around lines 69 - 75,
getAndRegisterHistoryService currently registers MockHistoryService without
stubbing, so tests will throw MissingStubError when methods are invoked; update
getAndRegisterHistoryService to either preconfigure common stubs on the mock
(e.g., set up typical method returns/behaviors used across tests) before calling
locator.registerSingleton<HistoryService>(service), or add a clear
docstring/comment above getAndRegisterHistoryService (similar to
getAndRegisterAuthenticationService/getAndRegisterHttpIOClientMock) stating that
callers must explicitly stub the mock before use; reference MockHistoryService
and HistoryService in the function body and mirror the stubbing pattern used by
getAndRegisterAuthenticationService and getAndRegisterHttpIOClientMock.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@lib/ui/widgets/smart_widgets/bottom_sheets/sort_bottom_sheet/sort_bottom_sheet_view.dart`:
- Around line 63-101: The code uses a non-existent RadioGroup widget and leaves
Radio widgets missing required parameters; replace the RadioGroup wrapper by
building each option with Flutter's standard Radio (or RadioListTile) pattern:
inside the ListView.builder iterate over Sort.values, call model.getSortMap()
once before the builder, and for each index use Radio(value: Sort.values[index],
groupValue: model.sortPreference, onChanged: (Sort? s) { if (s!=null) {
model.setSortPreference(completer, s); Navigator.of(context).pop(); } }), or use
RadioListTile with the same groupValue/onChanged and title from
sortMap[Sort.values[index]]; keep model.setSortPreference and
Navigator.of(context).pop() calls as shown and ensure you supply non-null labels
from getSortMap() when building items.

---

Outside diff comments:
In `@lib/ui/views/IRSSI/IRSSI_view.dart`:
- Around line 255-283: In the Container decoration inside the IRSSI view build
(the block creating subtitle1 and returning the Container), replace
Theme.of(context).colorScheme.background with
Theme.of(context).colorScheme.surface to avoid the deprecated background role;
update any similar uses in that widget (e.g., where the Container's color is
set) to use colorScheme.surface so the UI follows Material 3 color roles (keep
the rest of the ternary for dark mode unchanged).

---

Nitpick comments:
In `@test/helpers/test_helpers.dart`:
- Around line 69-75: getAndRegisterHistoryService currently registers
MockHistoryService without stubbing, so tests will throw MissingStubError when
methods are invoked; update getAndRegisterHistoryService to either preconfigure
common stubs on the mock (e.g., set up typical method returns/behaviors used
across tests) before calling locator.registerSingleton<HistoryService>(service),
or add a clear docstring/comment above getAndRegisterHistoryService (similar to
getAndRegisterAuthenticationService/getAndRegisterHttpIOClientMock) stating that
callers must explicitly stub the mock before use; reference MockHistoryService
and HistoryService in the function body and mirror the stubbing pattern used by
getAndRegisterAuthenticationService and getAndRegisterHttpIOClientMock.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9a1aa165-a012-41eb-a927-ea733979f0b0

📥 Commits

Reviewing files that changed from the base of the PR and between 3fa8364 and a436d52.

⛔ Files ignored due to path filters (1)
  • pubspec.lock is excluded by !**/*.lock
📒 Files selected for processing (15)
  • lib/theme/app_theme.dart
  • lib/ui/shared/shared_styles.dart
  • lib/ui/views/Download/download_view.dart
  • lib/ui/views/IRSSI/IRSSI_view.dart
  • lib/ui/views/disk_explorer/disk_explorer_view.dart
  • lib/ui/views/login/login_view.dart
  • lib/ui/widgets/dumb_widgets/document_type_card.dart
  • lib/ui/widgets/dumb_widgets/password_change_dialog_widget.dart
  • lib/ui/widgets/dumb_widgets/torrent_label_dialog.dart
  • lib/ui/widgets/smart_widgets/bottom_sheets/bottom_sheet_setup.dart
  • lib/ui/widgets/smart_widgets/bottom_sheets/confirm_bottom_sheet/confirm_bottom_sheet_view.dart
  • lib/ui/widgets/smart_widgets/bottom_sheets/sort_bottom_sheet/sort_bottom_sheet_view.dart
  • lib/ui/widgets/smart_widgets/url_bottom_sheet/url_bottomsheet_view.dart
  • pubspec.yaml
  • test/helpers/test_helpers.dart
💤 Files with no reviewable changes (1)
  • lib/theme/app_theme.dart

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a 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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@lib/ui/views/media_player/media_stream_viewmodel.dart`:
- Around line 86-87: The init() flow constructs _videoPlayerController with
VideoPlayerController.networkUrl(Uri.parse(_mediaUrl)) which can throw
FormatException; update init() in MediaStreamViewModel to validate or safely
parse the URL before passing it in (use Uri.tryParse and verify scheme/host or
wrap Uri.parse in a try/catch for FormatException), and if invalid, handle it
the same way PlatformException is handled (log via processLogger or state/error
field and abort controller creation) so malformed URLs do not crash the stream
flow; reference the _videoPlayerController assignment and the init() method when
making the change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 24f5c211-d5b2-4406-9bb7-74e1f5f3eb1c

📥 Commits

Reviewing files that changed from the base of the PR and between a436d52 and 10ea3f9.

📒 Files selected for processing (3)
  • lib/ui/views/media_player/media_stream_viewmodel.dart
  • lib/ui/widgets/smart_widgets/bottom_sheets/sort_bottom_sheet/sort_bottom_sheet_view.dart
  • test/helpers/test_helpers.mocks.dart
✅ Files skipped from review due to trivial changes (1)
  • test/helpers/test_helpers.mocks.dart
🚧 Files skipped from review as they are similar to previous changes (1)
  • lib/ui/widgets/smart_widgets/bottom_sheets/sort_bottom_sheet/sort_bottom_sheet_view.dart

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issues found when analyzed the project's dart code Used deprecated FlatButton in the codebase

1 participant