exportPlaces static method

Future<bool> exportPlaces(
  1. List<Place> places
)

Exports user's Pod places to a JSON file and triggers download.

Returns true if export was successful, false otherwise.

Implementation

static Future<bool> exportPlaces(List<Place> places) async {
  try {
    // Filter out local places - only export user's Pod data.
    final userPlaces = places.where((p) => !p.isLocal).toList();

    if (userPlaces.isEmpty) {
      return false;
    }

    final jsonList = userPlaces.map((p) => p.toJson()).toList();
    final jsonContent = const JsonEncoder.withIndent('  ').convert(jsonList);
    final bytes = Uint8List.fromList(utf8.encode(jsonContent));

    await FileSaver.instance.saveFile(
      name: 'places.json',
      bytes: bytes,
      mimeType: MimeType.json,
    );

    return true;
  } catch (_) {
    return false;
  }
}