Skip to content

Conversation

nope3472
Copy link
Contributor

@nope3472 nope3472 commented Sep 7, 2025

Fixes #1454

Changes

Introduced a feature to create animations by drawing 8 frames, preview them, save as animations, and transfer to badges.

Screenshots / Recordings

image image image image

Checklist:

  • No hard coding: I have used resources from constants.dart without hard coding any value.
  • No end of file edits: No modifications done at end of resource files.
  • Code reformatting: I have reformatted code and fixed indentation in every file included in this pull request.
  • Code analyzation: My code passes analyzations run in flutter analyze and tests run in flutter test.

Summary by Sourcery

Add custom multi-frame animation capabilities including a creator interface, file persistence, and a management screen

New Features:

  • Add CreateFramesScreen for drawing, navigating, and previewing up to 8 frames with undo/redo controls
  • Implement save dialog to name animations, select play speed, and persist frames as JSON
  • Introduce SavedFramesScreen to list, preview, and delete saved frame animations

Enhancements:

  • Extend FileHelper with methods to generate unique filenames and write frame animation payloads
  • Update navigation drawer and app routes to include "Create Your Own Frames" and "Saved Frame Animation" entries

Copy link
Contributor

sourcery-ai bot commented Sep 7, 2025

Reviewer's Guide

This PR implements a custom frame-based animation creator by extending FileHelper for saving JSON-encoded frames, adds two new navigation entries and routes for creating and browsing saved animations, introduces a full CreateFramesScreen with frame navigation, drawing history, preview and save dialog (with name sanitization and speed selection), and adds a SavedFramesScreen to list, preview and delete saved animations from storage.

Sequence diagram for saving a custom frame animation

sequenceDiagram
    actor User
    participant CreateFramesScreen
    participant FileHelper
    participant Storage
    User->>CreateFramesScreen: Clicks Save
    CreateFramesScreen->>FileHelper: saveFrameAnimationWithName(name, frames, speed)
    FileHelper->>Storage: Write frames_{sanitized_name}.json
    Storage-->>FileHelper: Success
    FileHelper-->>CreateFramesScreen: Save complete
    CreateFramesScreen-->>User: Show "Frames saved" toast
Loading

Sequence diagram for previewing a saved frame animation

sequenceDiagram
    actor User
    participant SavedFramesScreen
    participant Storage
    participant AnimationBadgeProvider
    User->>SavedFramesScreen: Clicks Play on saved animation
    SavedFramesScreen->>Storage: Read frames_{name}.json
    Storage-->>SavedFramesScreen: Return frame data
    SavedFramesScreen->>AnimationBadgeProvider: setNewGrid(stitched frames)
    SavedFramesScreen->>AnimationBadgeProvider: calculateDuration(speed)
    AnimationBadgeProvider-->>SavedFramesScreen: Animation ready
    SavedFramesScreen-->>User: Show animation preview
Loading

Class diagram for new and updated classes related to frame animation

classDiagram
    class FileHelper {
      +saveFrameAnimation(frames)
      +saveFrameAnimationWithName(name, frames, speed)
      -_generateFramesFilename()
    }
    class CreateFramesScreen {
      -_frames: List<List<List<int>>>
      -_currentFrame: int
      -_history: List<List<List<bool>>>
      +_saveFrames()
      +_nextFrame()
      +_prevFrame()
      +_undo()
      +_redo()
    }
    class SavedFramesScreen {
      -_saved: List<MapEntry<String, List<List<List<int>>>>>
      +_load()
    }
    FileHelper <.. CreateFramesScreen : uses
    SavedFramesScreen <.. FileHelper : uses
Loading

File-Level Changes

Change Details Files
Extended FileHelper with frame animation persistence
  • Added filename generator for frame JSON files
  • Implemented saveFrameAnimation and saveFrameAnimationWithName (with name sanitization and speed payload)
  • JSON-encode frame data and write to file via existing write API
lib/bademagic_module/utils/file_helper.dart
Updated navigation drawer to include frame animation entries
  • Inserted "Create Your Own Frames" and "Saved Frame Animation" items
  • Adjusted index values for existing tiles accordingly
lib/view/widgets/navigation_drawer.dart
Registered new routes for frame screens in main app
  • Imported CreateFramesScreen and SavedFramesScreen
  • Added '/createFrames' and '/savedFrames' route mappings
lib/main.dart
Added CreateFramesScreen for frame editing and saving
  • Enforce landscape orientation and manage 8-frame grid with DrawBadgeProvider
  • Implement frame navigation, undo/redo history and reset
  • Stitch frames for preview in save dialog with speed selector and name input
lib/view/create_frames_screen.dart
Added SavedFramesScreen to load and manage saved animations
  • Scan application directory for 'frames_' JSON files and parse payloads (with backward support)
  • Display list of saved animations with play (preview) and delete actions
  • Reuse AnimationBadgeProvider to render and control playback speed
lib/view/saved_frames_screen.dart

Assessment against linked issues

Issue Objective Addressed Explanation
#1454 Implement a feature to create custom frame animations.
#1454 Allow users to save custom frame animations.
#1454 Enable preview/playback of saved frame animations.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • The CreateFramesScreen class is over 400 lines and mixes UI, state management, and file logic—consider extracting parts (toolbar, frame navigator, save dialog) into smaller widgets or controllers to improve readability and testability.
  • The logic for ‘stitching’ frames into a single grid is duplicated in both save and load screens—extract that into a shared utility method to avoid code duplication and ease future updates.
  • Currently saveFrameAnimationWithName uses only the sanitized name as the filename, which could overwrite existing files if reused—consider appending a timestamp or unique ID to ensure filenames stay unique.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The CreateFramesScreen class is over 400 lines and mixes UI, state management, and file logic—consider extracting parts (toolbar, frame navigator, save dialog) into smaller widgets or controllers to improve readability and testability.
- The logic for ‘stitching’ frames into a single grid is duplicated in both save and load screens—extract that into a shared utility method to avoid code duplication and ease future updates.
- Currently saveFrameAnimationWithName uses only the sanitized name as the filename, which could overwrite existing files if reused—consider appending a timestamp or unique ID to ensure filenames stay unique.

## Individual Comments

### Comment 1
<location> `lib/view/create_frames_screen.dart:275` </location>
<code_context>
+
+    if (name == null || name.isEmpty) return;
+
+    await _fileHelper.saveFrameAnimationWithName(name, _frames, selectedSpeed);
+    ToastUtils().showToast("Frames saved");
+  }
</code_context>

<issue_to_address>
No error handling for save failures.

Add error handling to notify the user if saveFrameAnimationWithName fails due to an exception.
</issue_to_address>

### Comment 2
<location> `lib/view/saved_frames_screen.dart:30` </location>
<code_context>
+    for (final f in files) {
</code_context>

<issue_to_address>
Silent catch block may hide file loading errors.

Please log the exception or notify the user when file loading fails to aid debugging.
</issue_to_address>

### Comment 3
<location> `lib/view/saved_frames_screen.dart:157` </location>
<code_context>
+                                  },
+                                ),
+                                IconButton(
+                                  icon: const Icon(Icons.delete_outline),
+                                  onPressed: () async {
+                                    final dir =
+                                        await getApplicationDocumentsDirectory();
+                                    final path = '${dir.path}/${item.key}';
+                                    final f = File(path);
+                                    if (await f.exists()) await f.delete();
+                                    await _load();
+                                  },
+                                ),
</code_context>

<issue_to_address>
No confirmation before deleting saved frames.

Consider implementing a confirmation dialog to prevent accidental deletion of saved frames.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
                                IconButton(
                                  icon: const Icon(Icons.delete_outline),
                                  onPressed: () async {
                                    final dir =
                                        await getApplicationDocumentsDirectory();
                                    final path = '${dir.path}/${item.key}';
                                    final f = File(path);
                                    if (await f.exists()) await f.delete();
                                    await _load();
                                  },
                                ),
=======
                                IconButton(
                                  icon: const Icon(Icons.delete_outline),
                                  onPressed: () async {
                                    final confirm = await showDialog<bool>(
                                      context: context,
                                      builder: (BuildContext context) {
                                        return AlertDialog(
                                          title: const Text('Delete Frame'),
                                          content: const Text('Are you sure you want to delete this saved frame? This action cannot be undone.'),
                                          actions: [
                                            TextButton(
                                              onPressed: () => Navigator.of(context).pop(false),
                                              child: const Text('Cancel'),
                                            ),
                                            TextButton(
                                              onPressed: () => Navigator.of(context).pop(true),
                                              child: const Text('Delete'),
                                            ),
                                          ],
                                        );
                                      },
                                    );
                                    if (confirm == true) {
                                      final dir =
                                          await getApplicationDocumentsDirectory();
                                      final path = '${dir.path}/${item.key}';
                                      final f = File(path);
                                      if (await f.exists()) await f.delete();
                                      await _load();
                                    }
                                  },
                                ),
>>>>>>> REPLACE

</suggested_fix>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.


if (name == null || name.isEmpty) return;

await _fileHelper.saveFrameAnimationWithName(name, _frames, selectedSpeed);
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: No error handling for save failures.

Add error handling to notify the user if saveFrameAnimationWithName fails due to an exception.

Comment on lines +30 to +39
for (final f in files) {
try {
final content = await f.readAsString();
final data = jsonDecode(content);
List<List<List<int>>> frames;
if (data is List) {
// backward compatibility (no speed)
frames = (data)
.map((frame) => (frame as List<dynamic>)
.map((row) => (row as List<dynamic>).cast<int>())
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Silent catch block may hide file loading errors.

Please log the exception or notify the user when file loading fails to aid debugging.

Comment on lines +156 to +166
IconButton(
icon: const Icon(Icons.delete_outline),
onPressed: () async {
final dir =
await getApplicationDocumentsDirectory();
final path = '${dir.path}/${item.key}';
final f = File(path);
if (await f.exists()) await f.delete();
await _load();
},
),
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: No confirmation before deleting saved frames.

Consider implementing a confirmation dialog to prevent accidental deletion of saved frames.

Suggested change
IconButton(
icon: const Icon(Icons.delete_outline),
onPressed: () async {
final dir =
await getApplicationDocumentsDirectory();
final path = '${dir.path}/${item.key}';
final f = File(path);
if (await f.exists()) await f.delete();
await _load();
},
),
IconButton(
icon: const Icon(Icons.delete_outline),
onPressed: () async {
final confirm = await showDialog<bool>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('Delete Frame'),
content: const Text('Are you sure you want to delete this saved frame? This action cannot be undone.'),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(false),
child: const Text('Cancel'),
),
TextButton(
onPressed: () => Navigator.of(context).pop(true),
child: const Text('Delete'),
),
],
);
},
);
if (confirm == true) {
final dir =
await getApplicationDocumentsDirectory();
final path = '${dir.path}/${item.key}';
final f = File(path);
if (await f.exists()) await f.delete();
await _load();
}
},
),

Copy link
Contributor

github-actions bot commented Sep 7, 2025

Build Status

Build successful. APKs to test: https://github.com/fossasia/badgemagic-app/actions/runs/17548240363/artifacts/3952722329.

Screenshots

Android Screenshots
iPhone Screenshots
iPad Screenshots

Copy link
Member

@mariobehling mariobehling left a comment

Choose a reason for hiding this comment

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

Thank you. Please address sourcery-ai reviews.

@mariobehling
Copy link
Member

There is often a distortion of the images you upload on the PRs. This is due to a wrong ratio of the height and width. Could you please fix this and avoid these issues in future? Already pointed it out previously. It confuses in reviews.

@nope3472
Copy link
Contributor Author

nope3472 commented Sep 8, 2025

@mariobehling okay will use the correct ratios for uploading images

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.

feat: Add Custom Frame Animation Creator with Save & Playback Feature
2 participants