Stand up the Tanemaki monorepo and the first end-to-end vertical slice of Block 1 (offline, encrypted inventory): add a seed → see it in a categorized, searchable list → it persists → reopen and it's still there. Architecture (state management like G1nkgo, adapted to Tane's reality): - flutter_bloc (Cubit-first), but the encrypted Drift DB is the single source of truth; cubits stream from repositories (no hydrated_bloc/Hive, which would write plaintext at rest). - get_it composition root; go_router; slang i18n (ES/EN, Weblate-friendly JSON). Workspace & core: - pub workspace: packages/commons_core (pure Dart) + apps/app_seeds (Flutter). - commons_core primitives: UUIDv7 IdGen, Hybrid Logical Clock, Quantity value type (+ plant-aware QuantityKind), IdentityService root-seed stub. Data & security: - Drift schemaVersion=1 with all 10 Block-1 tables + common CRDT columns (HLC updated_at, last_author, tombstones); Movement append-only. - SQLCipher via an injectable executor that refuses to open a plaintext DB; DB key + root seed in the OS keystore (separate secrets). - Exported drift_schema_v1.json + migration scaffold. Tests (near-TDD; nothing merges without tests): - commons_core units (24), Drift migration test, "no plaintext at rest" security guard (runs where SQLCipher is present, skips otherwise), repository, widget, full quick-add flow, file-reopen persistence, and a no-hardcoded-strings i18n guard. GitLab CI: format + analyze + test + coverage. Follow-on Block-1 stories (item detail/edit, species catalog, germination UI) and all of Block 2 remain out of scope.
184 lines
5.8 KiB
Dart
184 lines
5.8 KiB
Dart
import 'dart:typed_data';
|
|
|
|
import 'package:commons_core/commons_core.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:image_picker/image_picker.dart';
|
|
|
|
import '../data/variety_repository.dart';
|
|
import '../i18n/strings.g.dart';
|
|
import '../state/quick_add_cubit.dart';
|
|
import 'quantity_kind_l10n.dart';
|
|
|
|
/// Picks a photo and returns its bytes (or null if cancelled). Injected so
|
|
/// widget tests can supply a fake instead of the camera plugin.
|
|
typedef PhotoPicker = Future<Uint8List?> Function();
|
|
|
|
/// A short, high-frequency subset of quantity units shown up front to keep the
|
|
/// add flow fast; the rest live behind "Add more…".
|
|
const _quickKinds = <QuantityKind>[
|
|
QuantityKind.aFew,
|
|
QuantityKind.handful,
|
|
QuantityKind.packet,
|
|
QuantityKind.pod,
|
|
QuantityKind.cob,
|
|
QuantityKind.grams,
|
|
];
|
|
|
|
Future<void> showQuickAddSheet(
|
|
BuildContext context, {
|
|
required VarietyRepository repository,
|
|
PhotoPicker? photoPicker,
|
|
}) {
|
|
return showModalBottomSheet<void>(
|
|
context: context,
|
|
isScrollControlled: true,
|
|
builder: (_) => BlocProvider(
|
|
create: (_) => QuickAddCubit(repository),
|
|
child: QuickAddSheet(photoPicker: photoPicker ?? _cameraPhotoPicker),
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<Uint8List?> _cameraPhotoPicker() async {
|
|
final file = await ImagePicker().pickImage(
|
|
source: ImageSource.camera,
|
|
maxWidth: 1280,
|
|
imageQuality: 80,
|
|
);
|
|
return file?.readAsBytes();
|
|
}
|
|
|
|
class QuickAddSheet extends StatelessWidget {
|
|
const QuickAddSheet({required this.photoPicker, super.key});
|
|
|
|
final PhotoPicker photoPicker;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final t = context.t;
|
|
return BlocConsumer<QuickAddCubit, QuickAddState>(
|
|
listenWhen: (prev, curr) => !prev.submitted && curr.submitted,
|
|
listener: (context, state) => Navigator.of(context).pop(),
|
|
builder: (context, state) {
|
|
final cubit = context.read<QuickAddCubit>();
|
|
return Padding(
|
|
padding: EdgeInsets.only(
|
|
left: 16,
|
|
right: 16,
|
|
top: 16,
|
|
bottom: MediaQuery.of(context).viewInsets.bottom + 16,
|
|
),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Text(
|
|
t.quickAdd.title,
|
|
style: Theme.of(context).textTheme.titleLarge,
|
|
),
|
|
const SizedBox(height: 12),
|
|
TextField(
|
|
key: const Key('quickAdd.labelField'),
|
|
autofocus: true,
|
|
textInputAction: TextInputAction.done,
|
|
decoration: InputDecoration(
|
|
labelText: t.quickAdd.labelField,
|
|
errorText: state.showLabelError
|
|
? t.quickAdd.labelRequired
|
|
: null,
|
|
border: const OutlineInputBorder(),
|
|
),
|
|
onChanged: cubit.labelChanged,
|
|
onSubmitted: (_) => cubit.submit(),
|
|
),
|
|
const SizedBox(height: 16),
|
|
Text(
|
|
t.quickAdd.quantity,
|
|
style: Theme.of(context).textTheme.labelLarge,
|
|
),
|
|
const SizedBox(height: 8),
|
|
Wrap(
|
|
spacing: 8,
|
|
children: [
|
|
for (final kind in _quickKinds)
|
|
ChoiceChip(
|
|
label: Text(quantityKindLabel(t, kind)),
|
|
selected: state.quantityKind == kind,
|
|
onSelected: (_) => cubit.selectQuantity(kind),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 8),
|
|
Align(
|
|
alignment: Alignment.centerLeft,
|
|
child: TextButton.icon(
|
|
onPressed: cubit.toggleExpanded,
|
|
icon: Icon(
|
|
state.expanded ? Icons.expand_less : Icons.expand_more,
|
|
),
|
|
label: Text(t.quickAdd.more),
|
|
),
|
|
),
|
|
if (state.expanded) _MoreSection(photoPicker: photoPicker),
|
|
const SizedBox(height: 8),
|
|
Row(
|
|
children: [
|
|
TextButton(
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
child: Text(t.quickAdd.cancel),
|
|
),
|
|
const Spacer(),
|
|
FilledButton(
|
|
key: const Key('quickAdd.save'),
|
|
onPressed: state.submitting ? null : cubit.submit,
|
|
child: Text(t.quickAdd.save),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
class _MoreSection extends StatelessWidget {
|
|
const _MoreSection({required this.photoPicker});
|
|
|
|
final PhotoPicker photoPicker;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final t = context.t;
|
|
final state = context.watch<QuickAddCubit>().state;
|
|
final cubit = context.read<QuickAddCubit>();
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
const SizedBox(height: 8),
|
|
if (state.photoBytes != null)
|
|
ClipRRect(
|
|
borderRadius: BorderRadius.circular(8),
|
|
child: Image.memory(
|
|
state.photoBytes!,
|
|
height: 120,
|
|
fit: BoxFit.cover,
|
|
),
|
|
),
|
|
Align(
|
|
alignment: Alignment.centerLeft,
|
|
child: OutlinedButton.icon(
|
|
onPressed: () async {
|
|
final bytes = await photoPicker();
|
|
if (bytes != null) cubit.photoPicked(bytes);
|
|
},
|
|
icon: const Icon(Icons.photo_camera_outlined),
|
|
label: Text(t.quickAdd.addPhoto),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|