-
-
Save kururu-abdo/bb2d1e5706f29d0e718dde3801154c3e 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