run method
the SimpleFrameApp subclass implements application-specific code
Implementation
@override
Future<void> run() async {
currentState = ApplicationState.running;
if (mounted) setState(() {});
try {
// Open the file picker
FilePickerResult? result = await FilePicker.platform.pickFiles(
type: FileType.custom,
allowedExtensions: ['txt'],
);
if (result != null) {
File file = File(result.files.single.path!);
// Read the file content and split into lines
String content = await file.readAsString();
_textChunks.clear();
// Update the UI
setState(() {
// strip out any carriage-return characters if the file is CRLF
content = content.replaceAll(RegExp('\r'), '');
_textChunks.addAll(content.split('\n'));
_currentLine = 0;
});
// and send initial text to Frame
await sendTextToFrame(_textChunks[_currentLine]);
}
else {
currentState = ApplicationState.ready;
if (mounted) setState(() {});
}
} catch (e) {
_log.fine('Error executing application logic: $e');
currentState = ApplicationState.ready;
if (mounted) setState(() {});
}
}