f1e88b1ac3
- Add shared_preferences for persisting server URL - Add SettingsService and PlatformService - Add server URL input field on non-web platforms - Make ApiConfig baseUrl configurable at runtime - Add Android location permissions (ACCESS_FINE/COURSE_LOCATION, INTERNET) - Request location permission on login and map init - Fix geo_id type: use String instead of int (UUID format) - Align share_service with API spec: remove unique_id, use share_id only - Fix watch endpoint response: last_update instead of created_at - Add error handling with SnackBars for geo operations - Wrap login screen in SingleChildScrollView for keyboard handling - Update map tile layer with userAgentPackageName for OSM
102 lines
2.4 KiB
Dart
102 lines
2.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../services/share_service.dart';
|
|
|
|
class ShareProvider with ChangeNotifier {
|
|
final ShareService _shareService;
|
|
|
|
String _shareId = '';
|
|
String _geoId = '';
|
|
bool _isLoading = false;
|
|
String _error = '';
|
|
|
|
Map<String, dynamic>? _position;
|
|
|
|
String _trackingShareId = '';
|
|
String _trackingToken = '';
|
|
Map<String, dynamic>? _trackedPosition;
|
|
|
|
ShareProvider({ShareService? shareService})
|
|
: _shareService = shareService ?? ShareService();
|
|
|
|
String get shareId => _shareId;
|
|
String get geoId => _geoId;
|
|
bool get isLoading => _isLoading;
|
|
String get error => _error;
|
|
Map<String, dynamic>? get position => _position;
|
|
|
|
String get trackingShareId => _trackingShareId;
|
|
Map<String, dynamic>? get trackedPosition => _trackedPosition;
|
|
|
|
Future<void> createShare(String token, double x, double y) async {
|
|
_isLoading = true;
|
|
_error = '';
|
|
notifyListeners();
|
|
|
|
try {
|
|
final result = await _shareService.createShare(token, x, y);
|
|
_geoId = result['geo_id']?.toString() ?? '';
|
|
_shareId = result['share_id']?.toString() ?? '';
|
|
notifyListeners();
|
|
} catch (e) {
|
|
_error = e.toString();
|
|
notifyListeners();
|
|
rethrow;
|
|
} finally {
|
|
_isLoading = false;
|
|
notifyListeners();
|
|
}
|
|
}
|
|
|
|
Future<void> getPosition(String token, String shareId) async {
|
|
_isLoading = true;
|
|
_error = '';
|
|
notifyListeners();
|
|
|
|
try {
|
|
_position = await _shareService.getPositionByShareId(token, shareId);
|
|
notifyListeners();
|
|
} catch (e) {
|
|
_error = e.toString();
|
|
notifyListeners();
|
|
rethrow;
|
|
} finally {
|
|
_isLoading = false;
|
|
notifyListeners();
|
|
}
|
|
}
|
|
|
|
void clearShare() {
|
|
_shareId = '';
|
|
_geoId = '';
|
|
_position = null;
|
|
notifyListeners();
|
|
}
|
|
|
|
Future<void> startTracking(String shareId, String token) async {
|
|
_trackingShareId = shareId;
|
|
_trackingToken = token;
|
|
_error = '';
|
|
notifyListeners();
|
|
|
|
await updateTrackedPosition();
|
|
}
|
|
|
|
Future<void> updateTrackedPosition() async {
|
|
if (_trackingShareId.isEmpty) return;
|
|
|
|
try {
|
|
_trackedPosition = await _shareService.getPositionByShareId(_trackingToken, _trackingShareId);
|
|
notifyListeners();
|
|
} catch (e) {
|
|
_error = e.toString();
|
|
notifyListeners();
|
|
}
|
|
}
|
|
|
|
void stopTracking() {
|
|
_trackingShareId = '';
|
|
_trackingToken = '';
|
|
_trackedPosition = null;
|
|
notifyListeners();
|
|
}
|
|
} |