loadFile method

Future<void> loadFile()

Calls addMessage for each message in the picked file.

Implementation

Future<void> loadFile() async {
	// Pick a file
	clear();
	isLoading = true;
	notifyListeners();
	final result = await FilePicker.platform.pickFiles(
		dialogTitle: "Choose science logs",
		initialDirectory: services.files.loggingDir.path,
	);
	if (result == null || result.count == 0) {
		isLoading = false;
		notifyListeners();
		return;
	}

	// Read the file
	final file = File(result.paths.first!);
	try {
		final messages = await services.files.readLogs(file);
		messages.forEach(addMessage);
		errorText = null;
		isLoading = false;
		isListening = false;
		models.home.setMessage(severity: Severity.info, text: "Science logs loaded, new data will be ignored");
		notifyListeners();
	} catch (error) {
		errorText = error.toString();
		isLoading = false;
		notifyListeners();
		rethrow;
	}
}