diff --git a/lib/screens/river/manual/widgets/river_in_situ_step_2_site_info.dart b/lib/screens/river/manual/widgets/river_in_situ_step_2_site_info.dart index aea08e4..46c6d7c 100644 --- a/lib/screens/river/manual/widgets/river_in_situ_step_2_site_info.dart +++ b/lib/screens/river/manual/widgets/river_in_situ_step_2_site_info.dart @@ -49,7 +49,18 @@ class _RiverInSituStep2SiteInfoState extends State { setState(() => _isPickingImage = true); final service = Provider.of(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) { setState(() => setImageCallback(file)); @@ -69,7 +80,6 @@ class _RiverInSituStep2SiteInfoState extends State { _formKey.currentState!.save(); - // UPDATED: Validation now checks for 3 required photos. if (widget.data.backgroundStationImage == null || widget.data.upstreamRiverImage == null || widget.data.downstreamRiverImage == null) { @@ -130,8 +140,6 @@ class _RiverInSituStep2SiteInfoState extends State { _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), - // REMOVED: The "Sample Turbidity" image picker was here. - const SizedBox(height: 24), const SizedBox(height: 32), @@ -193,4 +201,4 @@ class _RiverInSituStep2SiteInfoState extends State { ), ); } -} \ No newline at end of file +} diff --git a/lib/screens/river/manual/widgets/river_in_situ_step_4_additional_info.dart b/lib/screens/river/manual/widgets/river_in_situ_step_4_additional_info.dart index 1df2bf7..8b497a4 100644 --- a/lib/screens/river/manual/widgets/river_in_situ_step_4_additional_info.dart +++ b/lib/screens/river/manual/widgets/river_in_situ_step_4_additional_info.dart @@ -56,7 +56,18 @@ class _RiverInSituStep4AdditionalInfoState setState(() => _isPickingImage = true); final service = Provider.of(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) { setState(() => setImageCallback(file)); @@ -73,7 +84,6 @@ class _RiverInSituStep4AdditionalInfoState if (_formKey.currentState!.validate()) { _formKey.currentState!.save(); - // ADDED: Validation for the moved required photo. if (widget.data.sampleTurbidityImage == null) { _showSnackBar('Please attach the Sample Turbidity photo before proceeding.', isError: true); return; @@ -107,7 +117,6 @@ class _RiverInSituStep4AdditionalInfoState style: Theme.of(context).textTheme.headlineSmall), const SizedBox(height: 24), - // ADDED: The required "Sample Turbidity" photo moved from Step 2. Text("Required Photo *", style: Theme.of(context).textTheme.titleLarge), const SizedBox(height: 8), _buildImagePicker('Sample Turbidity', 'SAMPLE_TURBIDITY', widget.data.sampleTurbidityImage, (file) => widget.data.sampleTurbidityImage = file, isRequired: true), @@ -182,4 +191,4 @@ class _RiverInSituStep4AdditionalInfoState ), ); } -} \ No newline at end of file +} diff --git a/lib/services/river_in_situ_sampling_service.dart b/lib/services/river_in_situ_sampling_service.dart index 7a91ee8..197ec1a 100644 --- a/lib/services/river_in_situ_sampling_service.dart +++ b/lib/services/river_in_situ_sampling_service.dart @@ -43,6 +43,7 @@ class RiverInSituSamplingService { required RiverInSituSamplingData data, required String imageInfo, bool isRequired = false, + String? stationCode, // Accept station code for naming }) async { final picker = ImagePicker(); 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)); final tempDir = await getTemporaryDirectory(); - // CHANGED: Assumes the station code key for rivers is 'r_man_station_code'. Adjust if necessary. - final stationCode = data.selectedStation?['r_man_station_code'] ?? 'NA'; + final finalStationCode = stationCode ?? 'NA'; 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); return File(filePath)..writeAsBytesSync(img.encodeJpg(originalImage)); @@ -157,4 +157,4 @@ class RiverInSituSamplingService { imageFiles: data.toApiImageFiles(), ); } -} \ No newline at end of file +}