Last active
January 25, 2022 07:09
-
-
Save sergicastellsague/60a2453bb1d305e4e1e4a59ac1cdf8af to your computer and use it in GitHub Desktop.
Belongs to medium article
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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