Skip to content

Create chapter screen fix - #806

Open
mahmoudr80 wants to merge 3 commits into
AOSSIE-Org:masterfrom
mahmoudr80:create_chapter_screen_fix
Open

Create chapter screen fix#806
mahmoudr80 wants to merge 3 commits into
AOSSIE-Org:masterfrom
mahmoudr80:create_chapter_screen_fix

Conversation

@mahmoudr80

@mahmoudr80 mahmoudr80 commented Mar 29, 2026

Copy link
Copy Markdown

Description

In the create chapter screen I solved leak of memory cause of controller does not disposed.

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • [o] Bug fix (non-breaking CHANGE which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (does not change functionality, e.g. code style improvements, linting)
  • Documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

Please include screenshots below if applicable.

Checklist:

  • [o] My code follows the style guidelines of this project
  • [o] I have performed a self-review of my own code
  • [o] I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • [o] My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • [o] New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • [o] I have checked my code and corrected any misspellings

Maintainer Checklist

Summary by CodeRabbit

  • Bug Fixes
    • Improved stability when uploading audio and lyrics files by enhancing file selection handling.
    • Optimized resource management during chapter creation to prevent potential memory-related issues and improve application performance.

@mahmoudr80
mahmoudr80 requested a review from M4dhav as a code owner March 29, 2026 01:08
@github-actions

Copy link
Copy Markdown
Contributor

🎉 Welcome @mahmoudr80!
Thank you for your pull request! Our team will review it soon. 🔍

  • Please ensure your PR follows the contribution guidelines. ✅
  • All automated tests should pass before merging. 🔄
  • If this PR fixes an issue, link it in the description. 🔗

We appreciate your contribution! 🚀

@coderabbitai

coderabbitai Bot commented Mar 29, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This pull request fixes a memory leak in the create chapter screen by adding proper disposal of text controllers and improves null safety in file-picking methods by eliminating force-unwraps in favor of null checks.

Changes

Cohort / File(s) Summary
Memory Management & Null Safety
lib/views/screens/create_chapter_screen.dart
Added dispose() override to properly clean up titleController and aboutController. Updated pickAudioFile() and pickLyricsFile() to safely handle nullable file paths with nested null checks instead of force-unwrapping with path!.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Hop along, the leak is sealed,
Controllers now properly wheeled,
Null checks guard each file with care,
Memory flows with grace to spare!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR includes changes beyond the memory leak fix: nullable file path handling in pickAudioFile() and pickLyricsFile() methods appear unrelated to the controller disposal issue mentioned in issue #805. Separate the nullable file path handling changes into a distinct PR to keep this PR focused on fixing the memory leak as defined in issue #805.
Title check ❓ Inconclusive The title 'Create chapter screen fix' is vague and generic. While it indicates the component affected, it does not specifically communicate the primary change or the nature of the fix (memory leak/controller disposal). Consider using a more descriptive title like 'Fix memory leak in create chapter screen by disposing controllers' to clearly convey the main change.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The PR successfully addresses the primary objective from issue #805 by adding a dispose() override to properly dispose titleController and aboutController, directly fixing the memory leak caused by undisposed controllers.
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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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/views/screens/create_chapter_screen.dart`:
- Around line 59-62: The async file-picker handlers pickAudioFile() and
pickLyricsFile() call setState() after awaiting
FilePicker.platform.pickFiles(...) and can crash if the widget is disposed while
the picker is open; after each await result (i.e., immediately after the
FilePicker.platform.pickFiles(...) returns), add a guard "if (!mounted) return;"
before calling setState(), then proceed to setState(() => audioFile =
File(path)) and setState(() => lyricsFile = File(path)) respectively to avoid
setState() called after dispose() errors.
🪄 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: af7c2db0-242d-4947-bb33-df46ac5dcc57

📥 Commits

Reviewing files that changed from the base of the PR and between bf1dbe2 and 4dd220c.

📒 Files selected for processing (1)
  • lib/views/screens/create_chapter_screen.dart

Comment on lines +59 to +62
final path = result.files.single.path;
if (path != null) {
setState(() => audioFile = File(path));
}

@coderabbitai coderabbitai Bot Mar 29, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

cat -n lib/views/screens/create_chapter_screen.dart | head -150

Repository: AOSSIE-Org/Resonate

Length of output: 5429


Add mounted check after async file picker operations to prevent post-dispose crashes.

Both pickAudioFile() and pickLyricsFile() call setState() after await FilePicker.platform.pickFiles(...) without checking the mounted property. If the screen is closed while the picker is open, the setState() call will throw setState() called after dispose() when the picker returns.

Add if (!mounted) return; immediately after the await in both methods:

Suggested fix
  Future<void> pickAudioFile() async {
    FilePickerResult? result = await FilePicker.platform.pickFiles(
      type: FileType.custom,
      allowedExtensions: [
        'wav',
        'aiff',
        'alac',
        'flac',
        'mp3',
        'aac',
        'wma',
        'ogg',
      ],
    );
+   if (!mounted) return;

    if (result != null) {
      final path = result.files.single.path;
      if (path != null) {
        setState(() => audioFile = File(path));
      }
    }
  }

  Future<void> pickLyricsFile() async {
    FilePickerResult? result = await FilePicker.platform.pickFiles(
      type: FileType.custom,
      allowedExtensions: ['txt'],
    );
+   if (!mounted) return;

    if (result != null) {
-     if(result.files.single.path!=null){
+     if (result.files.single.path != null) {
        setState(() {
          lyricsFile = File(result.files.single.path!);
        });
      }
    }
  }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/views/screens/create_chapter_screen.dart` around lines 59 - 62, The async
file-picker handlers pickAudioFile() and pickLyricsFile() call setState() after
awaiting FilePicker.platform.pickFiles(...) and can crash if the widget is
disposed while the picker is open; after each await result (i.e., immediately
after the FilePicker.platform.pickFiles(...) returns), add a guard "if
(!mounted) return;" before calling setState(), then proceed to setState(() =>
audioFile = File(path)) and setState(() => lyricsFile = File(path)) respectively
to avoid setState() called after dispose() errors.

@4555jan 4555jan May 6, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mahmoudr80 please add the mounted check as code rabbit suggested

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@4555jan, sure! Here's the plan to add the mounted guard in both async file-picker methods:

  • Add if (!mounted) return; in pickAudioFile() after the await
  • Add if (!mounted) return; in pickLyricsFile() after the await
  • Fix minor spacing in the pickLyricsFile() null check

Failed to handle agent chat message. Please try again.

@4555jan

4555jan commented May 6, 2026

Copy link
Copy Markdown
Contributor

@mahmoudr80 also please open the PR to the dev branch only

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.

leak of memory in create_chapter_screen

2 participants