@@ -97,25 +97,32 @@ class _DrawBadgeState extends State<DrawBadge> {
9797 child: Column (
9898 mainAxisAlignment: MainAxisAlignment .center,
9999 children: [
100- // Main action buttons - centered and closer together
101100 Row (
102101 mainAxisAlignment: MainAxisAlignment .center,
103102 children: [
104- _buildCompactButton (true , Icons .edit, 'Draw' ),
105- const SizedBox (width: 8 ),
106- _buildCompactButton (false , Icons .delete, 'Erase' ),
107- const SizedBox (width: 8 ),
108- _buildResetButton (),
109- const SizedBox (width: 8 ),
110- _buildSaveButton (fileHelper),
111- const SizedBox (width: 8 ),
112- _buildShapesToggleButton (),
103+ Flexible (
104+ child: _buildCompactButton (
105+ true , Icons .edit, 'Draw' )),
106+ const SizedBox (width: 2 ),
107+ Flexible (
108+ child: _buildCompactButton (
109+ false , Icons .delete, 'Erase' )),
110+ const SizedBox (width: 2 ),
111+ Flexible (child: _buildResetButton ()),
112+ const SizedBox (width: 2 ),
113+ Flexible (child: _buildSaveButton (fileHelper)),
114+ const SizedBox (width: 2 ),
115+ Flexible (child: _buildShapesToggleButton ()),
116+ const SizedBox (width: 2 ),
117+ Flexible (child: _buildUndoButton ()),
118+ const SizedBox (width: 2 ),
119+ Flexible (child: _buildRedoButton ()),
113120 ],
114121 ),
122+ const SizedBox (height: 8 ),
115123 ],
116124 ),
117125 ),
118-
119126 // Shape options - only show when toggled, fixed height
120127 if (_showShapeOptions)
121128 Container (
@@ -126,16 +133,16 @@ class _DrawBadgeState extends State<DrawBadge> {
126133 children: [
127134 _buildCompactShapeCard (
128135 context, DrawShape .freehand, Icons .gesture, 'Free' ),
129- const SizedBox (width: 6 ),
136+ const SizedBox (width: 2 ),
130137 _buildCompactShapeCard (context, DrawShape .square,
131138 Icons .crop_square, 'Square' ),
132- const SizedBox (width: 6 ),
139+ const SizedBox (width: 2 ),
133140 _buildCompactShapeCard (context, DrawShape .rectangle,
134141 Icons .rectangle_outlined, 'Rect' ),
135- const SizedBox (width: 6 ),
142+ const SizedBox (width: 2 ),
136143 _buildCompactShapeCard (context, DrawShape .circle,
137144 Icons .circle_outlined, 'Circle' ),
138- const SizedBox (width: 6 ),
145+ const SizedBox (width: 2 ),
139146 _buildCompactShapeCard (context, DrawShape .triangle,
140147 Icons .change_history, 'Triangle' ),
141148 ],
@@ -202,7 +209,7 @@ class _DrawBadgeState extends State<DrawBadge> {
202209
203210 Widget _buildSaveButton (FileHelper fileHelper) {
204211 return TextButton (
205- onPressed: () {
212+ onPressed: () async {
206213 List <List <int >> badgeGrid = drawToggle
207214 .getDrawViewGrid ()
208215 .map ((e) => e.map ((e) => e ? 1 : 0 ).toList ())
@@ -211,19 +218,19 @@ class _DrawBadgeState extends State<DrawBadge> {
211218 Converters .convertBitmapToLEDHex (badgeGrid, false );
212219
213220 if (widget.isSavedCard! ) {
214- fileHelper.updateBadgeText (widget.filename! , hexString);
221+ await fileHelper.updateBadgeText (widget.filename! , hexString);
215222 } else if (widget.isSavedClipart! ) {
216- fileHelper.updateClipart (widget.filename! , badgeGrid);
223+ await fileHelper.updateClipart (widget.filename! , badgeGrid);
217224 } else {
218- fileHelper.saveImage (drawToggle.getDrawViewGrid ());
225+ await fileHelper.saveImage (drawToggle.getDrawViewGrid ());
219226 }
220227
221- fileHelper.generateClipartCache ();
228+ await fileHelper.generateClipartCache ();
222229 ToastUtils ().showToast ("Clipart Saved Successfully" );
223230
224- Future . delayed ( const Duration (milliseconds : 800 ), ( ) {
231+ if (mounted ) {
225232 Navigator .of (context).popUntil ((route) => route.isFirst);
226- });
233+ }
227234 },
228235 style: TextButton .styleFrom (
229236 padding: const EdgeInsets .symmetric (vertical: 4 , horizontal: 12 ),
@@ -271,6 +278,62 @@ class _DrawBadgeState extends State<DrawBadge> {
271278 );
272279 }
273280
281+ Widget _buildUndoButton () {
282+ return AnimatedBuilder (
283+ animation: drawToggle,
284+ builder: (context, _) {
285+ final bool canUndo = drawToggle.canUndo;
286+ final Color buttonColor = canUndo ? Colors .black : Colors .grey;
287+
288+ return TextButton (
289+ onPressed: canUndo
290+ ? () {
291+ drawToggle.undo ();
292+ }
293+ : null ,
294+ style: TextButton .styleFrom (
295+ padding: const EdgeInsets .symmetric (vertical: 4 , horizontal: 12 ),
296+ minimumSize: const Size (60 , 40 ),
297+ ),
298+ child: Column (
299+ mainAxisSize: MainAxisSize .min,
300+ children: [
301+ Icon (Icons .undo, color: buttonColor, size: 20 ),
302+ const SizedBox (height: 2 ),
303+ Text ('Undo' , style: TextStyle (color: buttonColor, fontSize: 10 )),
304+ ],
305+ ),
306+ );
307+ },
308+ );
309+ }
310+
311+ Widget _buildRedoButton () {
312+ return AnimatedBuilder (
313+ animation: drawToggle,
314+ builder: (context, _) {
315+ final bool canRedo = drawToggle.canRedo;
316+ final Color buttonColor = canRedo ? Colors .black : Colors .grey;
317+
318+ return TextButton (
319+ onPressed: canRedo ? drawToggle.redo : null ,
320+ style: TextButton .styleFrom (
321+ padding: const EdgeInsets .symmetric (vertical: 4 , horizontal: 12 ),
322+ minimumSize: const Size (60 , 40 ),
323+ ),
324+ child: Column (
325+ mainAxisSize: MainAxisSize .min,
326+ children: [
327+ Icon (Icons .redo, color: buttonColor, size: 20 ),
328+ const SizedBox (height: 2 ),
329+ Text ('Redo' , style: TextStyle (color: buttonColor, fontSize: 10 )),
330+ ],
331+ ),
332+ );
333+ },
334+ );
335+ }
336+
274337 Widget _buildCompactShapeCard (
275338 BuildContext context, DrawShape shape, IconData icon, String label) {
276339 final isSelected = drawToggle.selectedShape == shape;
0 commit comments