exportGpxToFile method

Future<String> exportGpxToFile([
  1. String? fileName
])

Exports the current route as a GPX file to device storage. Returns the path to the exported file.

Implementation

Future<String> exportGpxToFile([String? fileName]) async {
  try {
    final String? directoryPath = await getDownloadDirectoryPath();
    if (directoryPath == null) {
      throw Exception('Failed to get download directory path');
    }
    final String filePath =
        '$directoryPath/${fileName ?? 'route_${DateTime.now().millisecondsSinceEpoch}'}.gpx';
    final File file = File(filePath);
    await file.writeAsString(_currentRoute.value.toGPX());
    return filePath;
  } catch (e) {
    throw Exception('Failed to export GPX file: $e');
  }
}