repair river station name for local storage

This commit is contained in:
ALim Aidrus 2025-08-10 22:00:50 +08:00
parent 70bf72feaf
commit c7b97ecd1a
3 changed files with 30 additions and 13 deletions

View File

@ -49,7 +49,18 @@ class _RiverInSituStep2SiteInfoState extends State<RiverInSituStep2SiteInfo> {
setState(() => _isPickingImage = true); setState(() => _isPickingImage = true);
final service = Provider.of<RiverInSituSamplingService>(context, listen: false); final service = Provider.of<RiverInSituSamplingService>(context, listen: false);
final file = await service.pickAndProcessImage(source, data: widget.data, imageInfo: imageInfo, isRequired: isRequired);
// FIX: Get the station code directly from the data model.
final String? stationCode = widget.data.selectedStation?['sampling_station_code'];
// FIX: Pass the stationCode directly to the processing method.
final file = await service.pickAndProcessImage(
source,
data: widget.data,
imageInfo: imageInfo,
isRequired: isRequired,
stationCode: stationCode, // Pass the station code here
);
if (file != null) { if (file != null) {
setState(() => setImageCallback(file)); setState(() => setImageCallback(file));
@ -69,7 +80,6 @@ class _RiverInSituStep2SiteInfoState extends State<RiverInSituStep2SiteInfo> {
_formKey.currentState!.save(); _formKey.currentState!.save();
// UPDATED: Validation now checks for 3 required photos.
if (widget.data.backgroundStationImage == null || if (widget.data.backgroundStationImage == null ||
widget.data.upstreamRiverImage == null || widget.data.upstreamRiverImage == null ||
widget.data.downstreamRiverImage == null) { widget.data.downstreamRiverImage == null) {
@ -130,8 +140,6 @@ class _RiverInSituStep2SiteInfoState extends State<RiverInSituStep2SiteInfo> {
_buildImagePicker('Upstream River', 'UPSTREAM_RIVER', widget.data.upstreamRiverImage, (file) => widget.data.upstreamRiverImage = file, isRequired: true), _buildImagePicker('Upstream River', 'UPSTREAM_RIVER', widget.data.upstreamRiverImage, (file) => widget.data.upstreamRiverImage = file, isRequired: true),
_buildImagePicker('Downstream River', 'DOWNSTREAM_RIVER', widget.data.downstreamRiverImage, (file) => widget.data.downstreamRiverImage = file, isRequired: true), _buildImagePicker('Downstream River', 'DOWNSTREAM_RIVER', widget.data.downstreamRiverImage, (file) => widget.data.downstreamRiverImage = file, isRequired: true),
// REMOVED: The "Sample Turbidity" image picker was here.
const SizedBox(height: 24), const SizedBox(height: 24),
const SizedBox(height: 32), const SizedBox(height: 32),
@ -193,4 +201,4 @@ class _RiverInSituStep2SiteInfoState extends State<RiverInSituStep2SiteInfo> {
), ),
); );
} }
} }

View File

@ -56,7 +56,18 @@ class _RiverInSituStep4AdditionalInfoState
setState(() => _isPickingImage = true); setState(() => _isPickingImage = true);
final service = Provider.of<RiverInSituSamplingService>(context, listen: false); final service = Provider.of<RiverInSituSamplingService>(context, listen: false);
final file = await service.pickAndProcessImage(source, data: widget.data, imageInfo: imageInfo, isRequired: isRequired);
// FIX: Get the station code directly from the data model.
final String? stationCode = widget.data.selectedStation?['sampling_station_code'];
// FIX: Pass the stationCode directly to the processing method.
final file = await service.pickAndProcessImage(
source,
data: widget.data,
imageInfo: imageInfo,
isRequired: isRequired,
stationCode: stationCode, // Pass the station code here
);
if (file != null) { if (file != null) {
setState(() => setImageCallback(file)); setState(() => setImageCallback(file));
@ -73,7 +84,6 @@ class _RiverInSituStep4AdditionalInfoState
if (_formKey.currentState!.validate()) { if (_formKey.currentState!.validate()) {
_formKey.currentState!.save(); _formKey.currentState!.save();
// ADDED: Validation for the moved required photo.
if (widget.data.sampleTurbidityImage == null) { if (widget.data.sampleTurbidityImage == null) {
_showSnackBar('Please attach the Sample Turbidity photo before proceeding.', isError: true); _showSnackBar('Please attach the Sample Turbidity photo before proceeding.', isError: true);
return; return;
@ -107,7 +117,6 @@ class _RiverInSituStep4AdditionalInfoState
style: Theme.of(context).textTheme.headlineSmall), style: Theme.of(context).textTheme.headlineSmall),
const SizedBox(height: 24), const SizedBox(height: 24),
// ADDED: The required "Sample Turbidity" photo moved from Step 2.
Text("Required Photo *", style: Theme.of(context).textTheme.titleLarge), Text("Required Photo *", style: Theme.of(context).textTheme.titleLarge),
const SizedBox(height: 8), const SizedBox(height: 8),
_buildImagePicker('Sample Turbidity', 'SAMPLE_TURBIDITY', widget.data.sampleTurbidityImage, (file) => widget.data.sampleTurbidityImage = file, isRequired: true), _buildImagePicker('Sample Turbidity', 'SAMPLE_TURBIDITY', widget.data.sampleTurbidityImage, (file) => widget.data.sampleTurbidityImage = file, isRequired: true),
@ -182,4 +191,4 @@ class _RiverInSituStep4AdditionalInfoState
), ),
); );
} }
} }

View File

@ -43,6 +43,7 @@ class RiverInSituSamplingService {
required RiverInSituSamplingData data, required RiverInSituSamplingData data,
required String imageInfo, required String imageInfo,
bool isRequired = false, bool isRequired = false,
String? stationCode, // Accept station code for naming
}) async { }) async {
final picker = ImagePicker(); final picker = ImagePicker();
final XFile? photo = await picker.pickImage(source: source, imageQuality: 85, maxWidth: 1024); final XFile? photo = await picker.pickImage(source: source, imageQuality: 85, maxWidth: 1024);
@ -64,10 +65,9 @@ class RiverInSituSamplingService {
img.drawString(originalImage, watermarkTimestamp, font: font, x: 10, y: 10, color: img.ColorRgb8(0, 0, 0)); img.drawString(originalImage, watermarkTimestamp, font: font, x: 10, y: 10, color: img.ColorRgb8(0, 0, 0));
final tempDir = await getTemporaryDirectory(); final tempDir = await getTemporaryDirectory();
// CHANGED: Assumes the station code key for rivers is 'r_man_station_code'. Adjust if necessary. final finalStationCode = stationCode ?? 'NA';
final stationCode = data.selectedStation?['r_man_station_code'] ?? 'NA';
final fileTimestamp = "${data.samplingDate}-${data.samplingTime}".replaceAll(':', '-'); final fileTimestamp = "${data.samplingDate}-${data.samplingTime}".replaceAll(':', '-');
final newFileName = "${stationCode}_${fileTimestamp}_${imageInfo.replaceAll(' ', '')}.jpg"; final newFileName = "${finalStationCode}_${fileTimestamp}_${imageInfo.replaceAll(' ', '')}.jpg";
final filePath = path.join(tempDir.path, newFileName); final filePath = path.join(tempDir.path, newFileName);
return File(filePath)..writeAsBytesSync(img.encodeJpg(originalImage)); return File(filePath)..writeAsBytesSync(img.encodeJpg(originalImage));
@ -157,4 +157,4 @@ class RiverInSituSamplingService {
imageFiles: data.toApiImageFiles(), imageFiles: data.toApiImageFiles(),
); );
} }
} }