| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- import 'package:flutter/material.dart';
- import '../constants/mpob_colors.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("Correct Grade", 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(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("Remove this detection", style: TextStyle(color: colorScheme.error)),
- onTap: () => Navigator.pop(sheetContext, const ClassPickResult(remove: true)),
- ),
- ],
- const SizedBox(height: 8),
- ],
- ),
- );
- },
- );
- }
|