@@ -96,7 +96,7 @@ class _DrawBadgeState extends State<DrawBadge> {
96
96
_buildSaveButton (fileHelper),
97
97
_buildShapesToggleButton (),
98
98
99
- // ✅ New Undo & Redo buttons
99
+ // ✅ Updated Undo & Redo buttons with greyed out state
100
100
_buildUndoButton (),
101
101
_buildRedoButton (),
102
102
],
@@ -232,32 +232,44 @@ class _DrawBadgeState extends State<DrawBadge> {
232
232
}
233
233
234
234
Widget _buildUndoButton () {
235
+ // Check if undo is available using the getter
236
+ final bool canUndo = drawToggle.canUndo;
237
+ final Color buttonColor = canUndo ? Colors .black : Colors .grey;
238
+
235
239
return TextButton (
236
- onPressed: () {
237
- setState (() {
238
- drawToggle.undo ();
239
- });
240
- },
241
- child: const Column (
240
+ onPressed: canUndo
241
+ ? () {
242
+ setState (() {
243
+ drawToggle.undo ();
244
+ });
245
+ }
246
+ : null , // Disable button when can't undo
247
+ child: Column (
242
248
children: [
243
- Icon (Icons .undo, color: Colors .black ),
244
- Text ('Undo' , style: TextStyle (color: Colors .black )),
249
+ Icon (Icons .undo, color: buttonColor ),
250
+ Text ('Undo' , style: TextStyle (color: buttonColor )),
245
251
],
246
252
),
247
253
);
248
254
}
249
255
250
256
Widget _buildRedoButton () {
257
+ // Check if redo is available using the getter
258
+ final bool canRedo = drawToggle.canRedo;
259
+ final Color buttonColor = canRedo ? Colors .black : Colors .grey;
260
+
251
261
return TextButton (
252
- onPressed: () {
253
- setState (() {
254
- drawToggle.redo ();
255
- });
256
- },
257
- child: const Column (
262
+ onPressed: canRedo
263
+ ? () {
264
+ setState (() {
265
+ drawToggle.redo ();
266
+ });
267
+ }
268
+ : null , // Disable button when can't redo
269
+ child: Column (
258
270
children: [
259
- Icon (Icons .redo, color: Colors .black ),
260
- Text ('Redo' , style: TextStyle (color: Colors .black )),
271
+ Icon (Icons .redo, color: buttonColor ),
272
+ Text ('Redo' , style: TextStyle (color: buttonColor )),
261
273
],
262
274
),
263
275
);
0 commit comments