|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | + |
| 3 | +// Always show a certain button and depending on show show x more |
| 4 | +class CodeJudgeButtonMenu extends StatelessWidget{ |
| 5 | + final bool show; |
| 6 | + final IconData icon; |
| 7 | + final String label; |
| 8 | + final VoidCallback onDeselectPressed; |
| 9 | + final VoidCallback onUploadPressed; |
| 10 | + final VoidCallback onDeletePressed; |
| 11 | + final VoidCallback onButtonPressed; |
| 12 | + |
| 13 | + const CodeJudgeButtonMenu({ |
| 14 | + super.key, |
| 15 | + required this.show, |
| 16 | + required this.icon, |
| 17 | + required this.label, |
| 18 | + required this.onDeselectPressed, |
| 19 | + required this.onUploadPressed, |
| 20 | + required this.onDeletePressed, |
| 21 | + required this.onButtonPressed, |
| 22 | + }); |
| 23 | + |
| 24 | + @override |
| 25 | + Widget build(BuildContext context) { |
| 26 | + return Column( |
| 27 | + mainAxisSize: MainAxisSize.min, |
| 28 | + crossAxisAlignment: CrossAxisAlignment.end, |
| 29 | + children: [ |
| 30 | + // Animation while showing the other buttons |
| 31 | + AnimatedSwitcher( |
| 32 | + duration: Duration(milliseconds: 1000), |
| 33 | + child: show |
| 34 | + ? Padding( |
| 35 | + padding: const EdgeInsets.only(bottom: 12, right: 8.0), |
| 36 | + child: Column( |
| 37 | + mainAxisSize: MainAxisSize.min, |
| 38 | + crossAxisAlignment: CrossAxisAlignment.end, |
| 39 | + spacing: 6.0, |
| 40 | + children: [ |
| 41 | + // Deselect button |
| 42 | + FloatingActionButton.small( |
| 43 | + heroTag: "deselectButton", |
| 44 | + onPressed: onDeselectPressed, |
| 45 | + child: Icon(Icons.close_outlined) |
| 46 | + ), |
| 47 | + // Upload button |
| 48 | + FloatingActionButton.small( |
| 49 | + heroTag: "uploadButton", |
| 50 | + onPressed: onUploadPressed, |
| 51 | + child: Icon(Icons.upload_file_outlined), |
| 52 | + ), |
| 53 | + // Delete button |
| 54 | + FloatingActionButton.small( |
| 55 | + heroTag: "deleteButton", |
| 56 | + onPressed: onDeletePressed, |
| 57 | + child: Icon(Icons.delete_forever_outlined), |
| 58 | + ), |
| 59 | + ], |
| 60 | + ), |
| 61 | + ) |
| 62 | + : SizedBox.shrink(), |
| 63 | + ), |
| 64 | + // Always shown button |
| 65 | + FloatingActionButton.extended( |
| 66 | + icon: Icon(icon), |
| 67 | + label: Text(label), |
| 68 | + onPressed: onButtonPressed, |
| 69 | + ), |
| 70 | + ], |
| 71 | + ); |
| 72 | + } |
| 73 | +} |
0 commit comments