Skip to content

Instantly share code, notes, and snippets.

@kururu-abdo
Forked from sergicastellsague/main_screen.dart
Created January 25, 2022 07:09
Show Gist options
  • Save kururu-abdo/bb2d1e5706f29d0e718dde3801154c3e to your computer and use it in GitHub Desktop.
Save kururu-abdo/bb2d1e5706f29d0e718dde3801154c3e to your computer and use it in GitHub Desktop.
Belongs to medium article
class MainScreen extends StatefulWidget {
State createState() => MainScreenState();
}
class MainScreenState extends State<MainScreen> {
var _androidAppRetain = MethodChannel("android_app_retain");
@override
void initState() {
super.initState();
if (Platform.isAndroid) {
_androidAppRetain.invokeMethod("wasActivityKilled").then((result){
if (result){
showDialog(
context: context,
builder: (context) {
return ActivityGotKilledDialog();
});
}
});
}
}
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () {
if (Platform.isAndroid) {
if (Navigator.of(context).canPop()) {
return Future.value(true);
} else {
_androidAppRetain.invokeMethod("sendToBackground");
return Future.value(false);
}
} else {
return Future.value(true);
}
},
child: Scaffold(
drawer: MainDrawer(),
body: Stack(
children: <Widget>[
GoogleMap(),
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment