Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,18 @@ class MainActivity : FlutterActivity() {
super.configureFlutterEngine(flutterEngine)
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL)
.setMethodCallHandler { call, result ->
if (call.method == "getFileContent") {
result.success(fileContentToSend)
fileContentToSend = null // send only once
} else {
result.notImplemented()
when (call.method) {
"getFileContent" -> {
result.success(fileContentToSend)
fileContentToSend = null // send only once
}
"clearFileContent" -> {
fileContentToSend = null
result.success(null)
}
else -> {
result.notImplemented()
}
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions lib/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,16 @@ class _HomeState extends State<Home> {
}
}

Future<void> _clearFileContent() async {
try {
await _methodChannel.invokeMethod<void>('clearFileContent');
} on MissingPluginException {
debugPrint("Method channel not available on this platform");
} catch (e) {
debugPrint("Error clearing file content: $e");
}
}

Future<bool> _showExitConfirmationDialog() async {
return await showDialog<bool>(
context: context,
Expand Down Expand Up @@ -443,6 +453,7 @@ class _HomeState extends State<Home> {
}
final bool shouldPop = await _showExitConfirmationDialog();
if (shouldPop && context.mounted) {
await _clearFileContent();
await SystemNavigator.pop(animated: true);
}
},
Expand Down