@@ -97,25 +97,32 @@ class _DrawBadgeState extends State<DrawBadge> {
97
97
child: Column (
98
98
mainAxisAlignment: MainAxisAlignment .center,
99
99
children: [
100
- // Main action buttons - centered and closer together
101
100
Row (
102
101
mainAxisAlignment: MainAxisAlignment .center,
103
102
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 ()),
113
120
],
114
121
),
122
+ const SizedBox (height: 8 ),
115
123
],
116
124
),
117
125
),
118
-
119
126
// Shape options - only show when toggled, fixed height
120
127
if (_showShapeOptions)
121
128
Container (
@@ -126,16 +133,16 @@ class _DrawBadgeState extends State<DrawBadge> {
126
133
children: [
127
134
_buildCompactShapeCard (
128
135
context, DrawShape .freehand, Icons .gesture, 'Free' ),
129
- const SizedBox (width: 6 ),
136
+ const SizedBox (width: 2 ),
130
137
_buildCompactShapeCard (context, DrawShape .square,
131
138
Icons .crop_square, 'Square' ),
132
- const SizedBox (width: 6 ),
139
+ const SizedBox (width: 2 ),
133
140
_buildCompactShapeCard (context, DrawShape .rectangle,
134
141
Icons .rectangle_outlined, 'Rect' ),
135
- const SizedBox (width: 6 ),
142
+ const SizedBox (width: 2 ),
136
143
_buildCompactShapeCard (context, DrawShape .circle,
137
144
Icons .circle_outlined, 'Circle' ),
138
- const SizedBox (width: 6 ),
145
+ const SizedBox (width: 2 ),
139
146
_buildCompactShapeCard (context, DrawShape .triangle,
140
147
Icons .change_history, 'Triangle' ),
141
148
],
@@ -202,7 +209,7 @@ class _DrawBadgeState extends State<DrawBadge> {
202
209
203
210
Widget _buildSaveButton (FileHelper fileHelper) {
204
211
return TextButton (
205
- onPressed: () {
212
+ onPressed: () async {
206
213
List <List <int >> badgeGrid = drawToggle
207
214
.getDrawViewGrid ()
208
215
.map ((e) => e.map ((e) => e ? 1 : 0 ).toList ())
@@ -211,19 +218,19 @@ class _DrawBadgeState extends State<DrawBadge> {
211
218
Converters .convertBitmapToLEDHex (badgeGrid, false );
212
219
213
220
if (widget.isSavedCard! ) {
214
- fileHelper.updateBadgeText (widget.filename! , hexString);
221
+ await fileHelper.updateBadgeText (widget.filename! , hexString);
215
222
} else if (widget.isSavedClipart! ) {
216
- fileHelper.updateClipart (widget.filename! , badgeGrid);
223
+ await fileHelper.updateClipart (widget.filename! , badgeGrid);
217
224
} else {
218
- fileHelper.saveImage (drawToggle.getDrawViewGrid ());
225
+ await fileHelper.saveImage (drawToggle.getDrawViewGrid ());
219
226
}
220
227
221
- fileHelper.generateClipartCache ();
228
+ await fileHelper.generateClipartCache ();
222
229
ToastUtils ().showToast ("Clipart Saved Successfully" );
223
230
224
- Future . delayed ( const Duration (milliseconds : 800 ), ( ) {
231
+ if (mounted ) {
225
232
Navigator .of (context).popUntil ((route) => route.isFirst);
226
- });
233
+ }
227
234
},
228
235
style: TextButton .styleFrom (
229
236
padding: const EdgeInsets .symmetric (vertical: 4 , horizontal: 12 ),
@@ -271,6 +278,62 @@ class _DrawBadgeState extends State<DrawBadge> {
271
278
);
272
279
}
273
280
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
+
274
337
Widget _buildCompactShapeCard (
275
338
BuildContext context, DrawShape shape, IconData icon, String label) {
276
339
final isSelected = drawToggle.selectedShape == shape;
0 commit comments