class_picker_sheet.dart 2.3 KB

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