feat(block1): variety detail + edit screen with reactive lots
Tapping an inventory item now opens its detail (the /variety/:id route was a
placeholder). Read + edit one variety end-to-end:
- Detail view: photo, category, "also known as" names, notes and lots, driven
by a reactive VarietyDetailCubit.
- Edit core fields (label/category/notes, LWW) via a bottom sheet.
- Add a lot (harvest year + quantity) — the list refreshes reactively.
- Soft-delete (tombstone) with a confirm dialog.
Repository:
- watchVariety(id): merges Drift table-change streams (variety, lots, names,
attachments) via StreamGroup and reloads the full detail on any change, so a
lot added to a *different* table still refreshes the view.
- updateVariety (LWW), addLot, softDeleteVariety.
i18n: detail/edit/addLot strings (ES/EN); switched slang to {param} braces
interpolation (translator- and Weblate-friendly).
Tests: repository (reactive watchVariety, update, soft-delete) and widget tests
(render, edit updates title, add-lot appears, delete shows not-found). Full
suite green: 23 passing, 1 skipped (SQLCipher-only encryption guard).
This commit is contained in:
parent
040f15a898
commit
7ff4e38a15
15 changed files with 1093 additions and 18 deletions
68
apps/app_seeds/lib/state/variety_detail_cubit.dart
Normal file
68
apps/app_seeds/lib/state/variety_detail_cubit.dart
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:commons_core/commons_core.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../data/variety_repository.dart';
|
||||
|
||||
class VarietyDetailState extends Equatable {
|
||||
const VarietyDetailState({
|
||||
this.detail,
|
||||
this.loading = true,
|
||||
this.deleted = false,
|
||||
});
|
||||
|
||||
final VarietyDetail? detail;
|
||||
final bool loading;
|
||||
final bool deleted;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [detail, loading, deleted];
|
||||
}
|
||||
|
||||
/// Streams one variety's detail and edits it through the repository.
|
||||
class VarietyDetailCubit extends Cubit<VarietyDetailState> {
|
||||
VarietyDetailCubit(this._repo, this.varietyId)
|
||||
: super(const VarietyDetailState()) {
|
||||
_sub = _repo
|
||||
.watchVariety(varietyId)
|
||||
.listen(
|
||||
(d) => emit(
|
||||
VarietyDetailState(
|
||||
detail: d,
|
||||
loading: false,
|
||||
deleted: state.deleted,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final VarietyRepository _repo;
|
||||
final String varietyId;
|
||||
late final StreamSubscription<VarietyDetail?> _sub;
|
||||
|
||||
Future<void> updateFields({String? label, String? category, String? notes}) =>
|
||||
_repo.updateVariety(
|
||||
id: varietyId,
|
||||
label: label,
|
||||
category: category,
|
||||
notes: notes,
|
||||
);
|
||||
|
||||
Future<void> addLot({int? year, Quantity? quantity}) =>
|
||||
_repo.addLot(varietyId: varietyId, harvestYear: year, quantity: quantity);
|
||||
|
||||
Future<void> deleteVariety() async {
|
||||
await _repo.softDeleteVariety(varietyId);
|
||||
emit(
|
||||
VarietyDetailState(detail: state.detail, loading: false, deleted: true),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> close() async {
|
||||
await _sub.cancel();
|
||||
return super.close();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue