xxxxxxxxxx
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Close App Example'),
),
body: Center(
child: ElevatedButton(
child: Text('Close App'),
onPressed: () {
SystemNavigator.pop(); // This closes the Flutter app
},
),
),
),
);
}
}
xxxxxxxxxx
import 'package:flutter/services.dart';
void closeApp() {
SystemChannels.platform.invokeMethod('SystemNavigator.pop');
}