Skip to content

Create chapter screen fix contin.#807

Open
mahmoudr80 wants to merge 4 commits intoAOSSIE-Org:masterfrom
mahmoudr80:create_chapter_screen_fix2
Open

Create chapter screen fix contin.#807
mahmoudr80 wants to merge 4 commits intoAOSSIE-Org:masterfrom
mahmoudr80:create_chapter_screen_fix2

Conversation

@mahmoudr80
Copy link
Copy Markdown

@mahmoudr80 mahmoudr80 commented Mar 29, 2026

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.
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
    • Enhanced stability when selecting audio and lyrics files for chapter creation
    • Improved resource management to prevent potential memory issues and crashes

@mahmoudr80 mahmoudr80 requested a review from M4dhav as a code owner March 29, 2026 03:03
@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
Copy link
Copy Markdown

coderabbitai bot commented Mar 29, 2026

📝 Walkthrough

Walkthrough

The pull request fixes a memory leak in the create chapter screen by adding a dispose() override to properly release controllers, and improves null safety in file picking functions with mounted guards and explicit null checks for file paths.

Changes

Cohort / File(s) Summary
Memory Management & Null Safety
lib/views/screens/create_chapter_screen.dart
Added dispose() method override to release titleController and aboutController. Updated pickAudioFile and pickLyricsFile with mounted guards and null-aware handling of picked file paths, replacing unsafe forced unwrapping with conditional state updates.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A leaky screen we've made quite tight,
Controllers freed with all our might,
Null checks placed with careful care,
No memory left to drift in air! ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Create chapter screen fix contin.' is vague and appears incomplete ('contin.' suggests truncation), lacking clarity about the specific fix being applied. Revise the title to clearly specify the fix, e.g., 'Fix memory leak in create chapter screen by disposing controllers' for better clarity and completeness.
Out of Scope Changes check ❓ Inconclusive All changes align with fixing the memory leak; however, null safety improvements to pickAudioFile and pickLyricsFile appear tangential to the primary objective. Clarify whether the null safety enhancements in pickAudioFile and pickLyricsFile are necessary fixes or could be separated into a different PR for focused review.
✅ 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 code changes directly address issue #805 by adding a dispose() override to properly dispose titleController and aboutController, resolving the memory leak.
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.

Caution

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

⚠️ Outside diff range comments (1)
lib/views/screens/create_chapter_screen.dart (1)

68-83: ⚠️ Potential issue | 🟡 Minor

Missing mounted guard for consistency and safety.

pickAudioFile guards setState with if (!mounted) return; after the async file picker call, but pickLyricsFile lacks this guard. This inconsistency could cause a crash if the widget is disposed during file picking.

Additionally, the indentation is inconsistent with the rest of the file.

Proposed fix
   Future<void> pickLyricsFile() async {
     FilePickerResult? result = await FilePicker.platform.pickFiles(
       type: FileType.custom,
       allowedExtensions: ['txt'],
     );
 
-     
-  if (result != null) {
-   if(result.files.single.path!=null){
-     setState(() {
-       lyricsFile = File(result.files.single.path!);
-     });
-   }
-
-  }
+    if (!mounted) return;
+
+    if (result != null) {
+      final path = result.files.single.path;
+      if (path != null) {
+        setState(() => lyricsFile = File(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 68 - 83, The
pickLyricsFile method lacks the mounted check before calling setState which can
crash if the widget is disposed during the async FilePicker call; update
pickLyricsFile to return early if (!mounted) after the await
FilePicker.platform.pickFiles(...) and before calling setState (same pattern as
pickAudioFile), and also fix indentation to match surrounding code (ensure the
if (result != null) and nested path check are correctly indented and the
setState block aligns with other methods).
🧹 Nitpick comments (1)
lib/views/screens/create_chapter_screen.dart (1)

30-41: Consider adding mounted guard for consistency.

pickChapterCoverImage also calls setState after an async gap but lacks the mounted guard that was added to pickAudioFile. For consistency and safety, consider adding the same guard here.

Suggested change
   Future<void> pickChapterCoverImage() async {
     final ImagePicker picker = ImagePicker();
     final XFile? selectedImage = await picker.pickImage(
       source: ImageSource.gallery,
     );
 
+    if (!mounted) return;
+
     if (selectedImage != null) {
       setState(() {
         chapterCoverImage = File(selectedImage.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 30 - 41, The
pickChapterCoverImage function calls setState after awaiting picker.pickImage
and needs the same mounted guard used in pickAudioFile; update
pickChapterCoverImage (the async function) to return early if the widget is
unmounted (e.g., check if (!mounted) return;) after the await and before calling
setState so setState is only invoked when mounted.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@lib/views/screens/create_chapter_screen.dart`:
- Around line 68-83: The pickLyricsFile method lacks the mounted check before
calling setState which can crash if the widget is disposed during the async
FilePicker call; update pickLyricsFile to return early if (!mounted) after the
await FilePicker.platform.pickFiles(...) and before calling setState (same
pattern as pickAudioFile), and also fix indentation to match surrounding code
(ensure the if (result != null) and nested path check are correctly indented and
the setState block aligns with other methods).

---

Nitpick comments:
In `@lib/views/screens/create_chapter_screen.dart`:
- Around line 30-41: The pickChapterCoverImage function calls setState after
awaiting picker.pickImage and needs the same mounted guard used in
pickAudioFile; update pickChapterCoverImage (the async function) to return early
if the widget is unmounted (e.g., check if (!mounted) return;) after the await
and before calling setState so setState is only invoked when mounted.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: faac41a2-7a26-4634-ab07-ecb15d90956b

📥 Commits

Reviewing files that changed from the base of the PR and between bf1dbe2 and 8ca529b.

📒 Files selected for processing (1)
  • lib/views/screens/create_chapter_screen.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.

leak of memory in create_chapter_screen

1 participant