| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- import 'package:flutter/material.dart';
- import '../constants/mpob_colors.dart';
- import '../services/app_strings.dart';
- /// Result of [showClassPickerSheet]: either a picked [className], or
- /// [remove] set when the harvester chose to delete the detection entirely.
- class ClassPickResult {
- final String? className;
- final bool remove;
- const ClassPickResult({this.className, this.remove = false});
- }
- /// Shared MPOB class-picker bottom sheet, used both to correct an existing
- /// detection's grade and to grade a newly-added one.
- Future<ClassPickResult?> showClassPickerSheet(
- BuildContext context, {
- required String? currentClass,
- bool showRemoveOption = false,
- }) {
- final colorScheme = Theme.of(context).colorScheme;
- return showModalBottomSheet<ClassPickResult>(
- context: context,
- shape: const RoundedRectangleBorder(borderRadius: BorderRadius.vertical(top: Radius.circular(20))),
- builder: (sheetContext) {
- return SafeArea(
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- Padding(
- padding: const EdgeInsets.fromLTRB(20, 20, 20, 8),
- child: Align(
- alignment: Alignment.centerLeft,
- child: Text(AppStrings.t('correct_grade_title'), style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: colorScheme.onSurface)),
- ),
- ),
- ...mpobClasses.map((className) {
- return ListTile(
- leading: Container(width: 14, height: 14, decoration: BoxDecoration(color: getMPOBColor(className), shape: BoxShape.circle)),
- title: Text(AppStrings.className(className)),
- trailing: currentClass == className ? const Icon(Icons.check) : null,
- onTap: () => Navigator.pop(sheetContext, ClassPickResult(className: className)),
- );
- }),
- if (showRemoveOption) ...[
- const Divider(height: 1),
- ListTile(
- leading: Icon(Icons.delete_outline, color: colorScheme.error),
- title: Text(AppStrings.t('remove_detection_button'), style: TextStyle(color: colorScheme.error)),
- onTap: () => Navigator.pop(sheetContext, const ClassPickResult(remove: true)),
- ),
- ],
- const SizedBox(height: 8),
- ],
- ),
- );
- },
- );
- }
|