Create chapter screen fix contin.#807
Conversation
|
🎉 Welcome @mahmoudr80!
We appreciate your contribution! 🚀 |
📝 WalkthroughWalkthroughThe 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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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 | 🟡 MinorMissing
mountedguard for consistency and safety.
pickAudioFileguardssetStatewithif (!mounted) return;after the async file picker call, butpickLyricsFilelacks 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 addingmountedguard for consistency.
pickChapterCoverImagealso callssetStateafter an async gap but lacks themountedguard that was added topickAudioFile. 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
📒 Files selected for processing (1)
lib/views/screens/create_chapter_screen.dart
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.
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:
Maintainer Checklist
Summary by CodeRabbit