91 lines
2.2 KiB
Dart
91 lines
2.2 KiB
Dart
import 'package:flutter/services.dart';
|
|
|
|
class CarPlatformBridge {
|
|
CarPlatformBridge._();
|
|
|
|
static const _channel = MethodChannel('com.tripz.tripz_driver/car_navigation');
|
|
|
|
static bool _isInitialized = false;
|
|
|
|
static void ensureInitialized() {
|
|
if (_isInitialized) return;
|
|
_channel.setMethodCallHandler(_handleMethodCall);
|
|
_isInitialized = true;
|
|
}
|
|
|
|
static Future<dynamic> _handleMethodCall(MethodCall call) async {
|
|
switch (call.method) {
|
|
case 'isCarAppConnected':
|
|
return false;
|
|
default:
|
|
throw MissingPluginException();
|
|
}
|
|
}
|
|
|
|
static Future<void> updateNavState({
|
|
required double lat,
|
|
required double lng,
|
|
required double bearing,
|
|
required double speed,
|
|
required String instruction,
|
|
required double distanceToStep,
|
|
required double totalDistance,
|
|
required double eta,
|
|
required int maneuver,
|
|
required bool isNavigating,
|
|
bool isMapDarkMode = false,
|
|
}) async {
|
|
try {
|
|
await _channel.invokeMethod('updateNavState', {
|
|
'lat': lat,
|
|
'lng': lng,
|
|
'bearing': bearing,
|
|
'speed': speed,
|
|
'instruction': instruction,
|
|
'distanceToStep': distanceToStep,
|
|
'totalDistance': totalDistance,
|
|
'eta': eta,
|
|
'maneuver': maneuver,
|
|
'isNavigating': isNavigating,
|
|
'isMapDarkMode': isMapDarkMode,
|
|
});
|
|
} catch (_) {}
|
|
}
|
|
|
|
static Future<void> updateLocation({
|
|
required double lat,
|
|
required double lng,
|
|
required double bearing,
|
|
required double speed,
|
|
}) async {
|
|
try {
|
|
await _channel.invokeMethod('updateLocation', {
|
|
'lat': lat,
|
|
'lng': lng,
|
|
'bearing': bearing,
|
|
'speed': speed,
|
|
});
|
|
} catch (_) {}
|
|
}
|
|
|
|
static Future<void> updateInstruction({
|
|
required String instruction,
|
|
required int maneuver,
|
|
required double distanceToStep,
|
|
}) async {
|
|
try {
|
|
await _channel.invokeMethod('updateInstruction', {
|
|
'instruction': instruction,
|
|
'maneuver': maneuver,
|
|
'distanceToStep': distanceToStep,
|
|
});
|
|
} catch (_) {}
|
|
}
|
|
|
|
static Future<void> stopNavigation() async {
|
|
try {
|
|
await _channel.invokeMethod('stopNavigation');
|
|
} catch (_) {}
|
|
}
|
|
}
|