Created
February 7, 2023 20:20
-
-
Save HansMuller/94745abd6fb880c40dfc188cdc6c7fc2 to your computer and use it in GitHub Desktop.
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
import 'package:flutter/widgets.dart'; | |
class Application with WidgetsBindingObserver { | |
final Widget home; | |
final Function onLaunch; | |
final Function onTerminate; | |
Application({ | |
@required this.home, | |
this.onLaunch, | |
this.onTerminate, | |
}) { | |
WidgetsBinding.instance.addObserver(this); | |
} | |
void run() { | |
runApp(home); | |
} | |
@override | |
void didChangeAppLifecycleState(AppLifecycleState state) { | |
switch (state) { | |
case AppLifecycleState.initiated: | |
if (onLaunch != null) { | |
onLaunch(); | |
} | |
break; | |
case AppLifecycleState.paused: | |
case AppLifecycleState.inactive: | |
case AppLifecycleState.detached: | |
if (onTerminate != null) { | |
onTerminate(); | |
} | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment