From ff9db26cae4a8ed5b6dac2b676dad309d9a54ebf Mon Sep 17 00:00:00 2001 From: TobiasRoeddiger Date: Fri, 2 Oct 2026 11:42:18 +0200 Subject: [PATCH] fix(seal-check): save Android JSON through document picker --- .../audio_response_measurement_view.dart | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/open_wearable/lib/apps/seal_check/audio_response_measurement_view.dart b/open_wearable/lib/apps/seal_check/audio_response_measurement_view.dart index 117649718..54a1b9123 100644 --- a/open_wearable/lib/apps/seal_check/audio_response_measurement_view.dart +++ b/open_wearable/lib/apps/seal_check/audio_response_measurement_view.dart @@ -104,14 +104,14 @@ class _SealCheckMeasurementViewState extends State { final fileName = 'seal_check_${_timestampForFilename(now)}.json'; if (Platform.isAndroid) { - final dirPath = await FilePicker.getDirectoryPath(); - if (dirPath == null || dirPath.isEmpty) return null; - final String path = p.join(dirPath, fileName); - await File(path).writeAsString( - const JsonEncoder.withIndent(' ').convert(result), - flush: true, + final uri = await FilePicker.saveFile( + fileName: fileName, + mimeType: 'application/json', + bytes: Uint8List.fromList( + utf8.encode(const JsonEncoder.withIndent(' ').convert(result)), + ), ); - return path; + return uri?.toString(); } Directory? downloads; @@ -201,11 +201,13 @@ class _SealCheckMeasurementViewState extends State { if (_rightResult != null) 'right': _rightResult!.toJson(), }; - final path = - await _saveResultToDownloadsAsJson(combined); - final msg = path == null - ? 'Not saved — either not supported or you canceled.' - : 'Saved to: $path'; + String msg; + try { + final path = await _saveResultToDownloadsAsJson(combined); + msg = path == null ? 'Save canceled.' : 'Saved to: $path'; + } catch (error) { + msg = 'Could not save JSON: $error'; + } if (!context.mounted) return; ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: Text(msg)),