class_picker_sheet.dart 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import 'package:flutter/material.dart';
  2. import '../constants/mpob_colors.dart';
  3. /// Result of [showClassPickerSheet]: either a picked [className], or
  4. /// [remove] set when the harvester chose to delete the detection entirely.
  5. class ClassPickResult {
  6. final String? className;
  7. final bool remove;
  8. const ClassPickResult({this.className, this.remove = false});
  9. }
  10. /// Shared MPOB class-picker bottom sheet, used both to correct an existing
  11. /// detection's grade and to grade a newly-added one.
  12. Future<ClassPickResult?> showClassPickerSheet(
  13. BuildContext context, {
  14. required String? currentClass,
  15. bool showRemoveOption = false,
  16. }) {
  17. final colorScheme = Theme.of(context).colorScheme;
  18. return showModalBottomSheet<ClassPickResult>(
  19. context: context,
  20. shape: const RoundedRectangleBorder(borderRadius: BorderRadius.vertical(top: Radius.circular(20))),
  21. builder: (sheetContext) {
  22. return SafeArea(
  23. child: Column(
  24. mainAxisSize: MainAxisSize.min,
  25. children: [
  26. Padding(
  27. padding: const EdgeInsets.fromLTRB(20, 20, 20, 8),
  28. child: Align(
  29. alignment: Alignment.centerLeft,
  30. child: Text("Correct Grade", style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: colorScheme.onSurface)),
  31. ),
  32. ),
  33. ...mpobClasses.map((className) {
  34. return ListTile(
  35. leading: Container(width: 14, height: 14, decoration: BoxDecoration(color: getMPOBColor(className), shape: BoxShape.circle)),
  36. title: Text(className),
  37. trailing: currentClass == className ? const Icon(Icons.check) : null,
  38. onTap: () => Navigator.pop(sheetContext, ClassPickResult(className: className)),
  39. );
  40. }),
  41. if (showRemoveOption) ...[
  42. const Divider(height: 1),
  43. ListTile(
  44. leading: Icon(Icons.delete_outline, color: colorScheme.error),
  45. title: Text("Remove this detection", style: TextStyle(color: colorScheme.error)),
  46. onTap: () => Navigator.pop(sheetContext, const ClassPickResult(remove: true)),
  47. ),
  48. ],
  49. const SizedBox(height: 8),
  50. ],
  51. ),
  52. );
  53. },
  54. );
  55. }