-
Notifications
You must be signed in to change notification settings - Fork 21
feat: Add Dynamic Auto-Resizing Text Editor #286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: Add Dynamic Auto-Resizing Text Editor #286
Conversation
Reviewer's GuideAdds a new TextFitEditor widget for dynamic, auto-resizing text editing and integrates it into the image editor's BottomActionMenu, enabling users to insert text that always fits the canvas and export it as an image. Sequence diagram for adding text via TextFitEditorsequenceDiagram
actor User
participant "BottomActionMenu"
participant "TextFitEditor"
participant "imgLoader"
User->>"BottomActionMenu": Tap 'Text' button
"BottomActionMenu"->>"TextFitEditor": Open editor with canvas size
User->>"TextFitEditor": Enter text, select options
"TextFitEditor"->>"BottomActionMenu": Return exported image bytes
"BottomActionMenu"->>"imgLoader": updateImage(bytes)
"BottomActionMenu"->>"imgLoader": saveFinalizedImageBytes(bytes)
"BottomActionMenu"->>User: Show updated canvas
Class diagram for new TextFitEditor widgetclassDiagram
class TextFitEditor {
+int width
+int height
+TextFitEditor(width, height)
}
class TextFitEditorState {
-TextEditingController _controller
-GlobalKey _repaintKey
-Color _textColor
-Color _backgroundColor
-TextAlign _align
-List<Color> _availableColors
+initState()
+build(context)
+_calculateCanvas(screenSize)
+_fitFontSize(text, maxW, maxH, align)
+_export(canvasSize)
}
TextFitEditor o-- TextFitEditorState
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this 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:
- Dispose the TextEditingController in TextFitEditorState.dispose to avoid memory leaks.
- Wrap the editor UI in a SafeArea or handle keyboard insets so the text field and controls aren’t obscured by system UI or the keyboard.
- Consider extracting the font fitting binary‐search logic (_fitFontSize) into a separate utility to improve reusability and testability.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Dispose the TextEditingController in TextFitEditorState.dispose to avoid memory leaks.
- Wrap the editor UI in a SafeArea or handle keyboard insets so the text field and controls aren’t obscured by system UI or the keyboard.
- Consider extracting the font fitting binary‐search logic (_fitFontSize) into a separate utility to improve reusability and testability.
## Individual Comments
### Comment 1
<location> `lib/view/text_fit_editor.dart:79-83` </location>
<code_context>
+ }
+
+ Future<Uint8List?> _export(Size canvasSize) async {
+ final boundary = _repaintKey.currentContext?.findRenderObject()
+ as RenderRepaintBoundary?;
+ if (boundary == null) return null;
+ final pixelRatio = widget.width / canvasSize.width;
+ final ui.Image image = await boundary.toImage(pixelRatio: pixelRatio);
+ final ui.ByteData? data =
+ await image.toByteData(format: ui.ImageByteFormat.png);
</code_context>
<issue_to_address>
**issue (bug_risk):** Check for zero or negative pixelRatio before calling toImage.
A guard clause to ensure pixelRatio is positive will prevent runtime errors if canvasSize.width is zero or negative.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Fixes: #284
Add a dynamic Text Editor where text always fits inside a fixed canvas by auto-resizing as content grows. On finalize, the text should export as an image similar to other elements.
Here is the demo video of this feature:
textfit_editor.mp4
Summary by Sourcery
Add a dynamic text editor that auto-resizes content to fit a fixed canvas and exports the final text as an image
New Features: