diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index f507a7f..01e4a58 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -27,9 +27,9 @@
-
+
diff --git a/lib/auth_provider.dart b/lib/auth_provider.dart
index 1c0247b..0c68437 100644
--- a/lib/auth_provider.dart
+++ b/lib/auth_provider.dart
@@ -267,6 +267,27 @@ class AuthProvider with ChangeNotifier {
}
}
+ // --- START: NEW METHOD FOR REGISTRATION SCREEN ---
+ Future syncRegistrationData() async {
+ final connectivityResult = await Connectivity().checkConnectivity();
+ if (connectivityResult.contains(ConnectivityResult.none)) {
+ debugPrint("AuthProvider: Device is OFFLINE. Skipping registration data sync.");
+ return;
+ }
+
+ debugPrint("AuthProvider: Fetching data for registration screen...");
+ final result = await _apiService.syncRegistrationData();
+
+ if (result['success']) {
+ await _loadDataFromCache(); // Reload data from DB into the provider
+ notifyListeners(); // Notify the UI to rebuild
+ debugPrint("AuthProvider: Registration data loaded and UI notified.");
+ } else {
+ debugPrint("AuthProvider: Registration data sync failed.");
+ }
+ }
+ // --- END: NEW METHOD FOR REGISTRATION SCREEN ---
+
Future refreshProfile() async {
final connectivityResult = await Connectivity().checkConnectivity();
if (connectivityResult.contains(ConnectivityResult.none)) {
diff --git a/lib/screens/marine/manual/widgets/in_situ_step_1_sampling_info.dart b/lib/screens/marine/manual/widgets/in_situ_step_1_sampling_info.dart
index bfd4089..c8ca92f 100644
--- a/lib/screens/marine/manual/widgets/in_situ_step_1_sampling_info.dart
+++ b/lib/screens/marine/manual/widgets/in_situ_step_1_sampling_info.dart
@@ -8,9 +8,7 @@ import 'package:simple_barcode_scanner/simple_barcode_scanner.dart';
import '../../../../auth_provider.dart';
import '../../../../models/in_situ_sampling_data.dart';
-// START CHANGE: Import the new, correct service file
import '../../../../services/marine_in_situ_sampling_service.dart';
-// END CHANGE
class InSituStep1SamplingInfo extends StatefulWidget {
final InSituSamplingData data;
@@ -90,6 +88,10 @@ class _InSituStep1SamplingInfoState extends State {
_dateController.text = widget.data.samplingDate!;
_timeController.text = widget.data.samplingTime!;
+ if (widget.data.samplingType == null) {
+ widget.data.samplingType = 'Schedule';
+ }
+
final allStations = auth.manualStations ?? [];
if (allStations.isNotEmpty) {
final states = allStations.map((s) => s['state_name'] as String?).whereType().toSet().toList();
@@ -110,7 +112,8 @@ class _InSituStep1SamplingInfoState extends State {
.where((s) =>
s['state_name'] == widget.data.selectedStateName &&
s['category_name'] == widget.data.selectedCategoryName)
- .toList();
+ .toList()
+ ..sort((a, b) => (a['man_station_code'] ?? '').compareTo(b['man_station_code'] ?? ''));
}
setState(() {
@@ -121,9 +124,7 @@ class _InSituStep1SamplingInfoState extends State {
Future _getCurrentLocation() async {
setState(() => _isLoadingLocation = true);
- // START CHANGE: Use the correct, new service type from Provider
final service = Provider.of(context, listen: false);
- // END CHANGE
try {
final position = await service.getCurrentLocation();
@@ -154,9 +155,7 @@ class _InSituStep1SamplingInfoState extends State {
final lon2Str = widget.data.currentLongitude;
if (lat1Str != null && lon1Str != null && lat2Str != null && lon2Str != null) {
- // START CHANGE: Use the correct, new service type from Provider
final service = Provider.of(context, listen: false);
- // END CHANGE
final lat1 = double.tryParse(lat1Str);
final lon1 = double.tryParse(lon1Str);
final lat2 = double.tryParse(lat2Str);
@@ -184,31 +183,113 @@ class _InSituStep1SamplingInfoState extends State {
}
}
- /// Validates the form and distance, then proceeds to the next step.
+ // --- START: New function to find and show nearby stations ---
+ Future _findAndShowNearbyStations() async {
+ if (widget.data.currentLatitude == null || widget.data.currentLatitude!.isEmpty) {
+ await _getCurrentLocation();
+ if (!mounted || widget.data.currentLatitude == null || widget.data.currentLatitude!.isEmpty) {
+ return;
+ }
+ }
+
+ final service = Provider.of(context, listen: false);
+ final auth = Provider.of(context, listen: false);
+
+ final currentLat = double.parse(widget.data.currentLatitude!);
+ final currentLon = double.parse(widget.data.currentLongitude!);
+ final allStations = auth.manualStations ?? [];
+ final List