Created
January 14, 2019 10:56
-
-
Save westdabestdb/d6c7b9a008016b44bd6fa19b645d33e7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 ScreenOne extends StatefulWidget { | |
@override | |
_ScreenOneState createState() => _ScreenOneState(); | |
} | |
class _ScreenOneState extends State<ScreenOne> with WidgetsBindingObserver { | |
String _platformVersion = 'Unknown'; | |
String _statusMessage = "waiting for camera permission"; | |
Permission permission; | |
@override | |
void initState() { | |
super.initState(); | |
initPlatformState(); | |
WidgetsBinding.instance.addObserver(this); | |
requestPermission(); | |
} | |
initPlatformState() async { | |
String platformVersion; | |
try { | |
platformVersion = await SimplePermissions.platformVersion; | |
} on PlatformException { | |
platformVersion = 'Failed to get platform version.'; | |
} | |
if (!mounted) return; | |
setState(() { | |
_platformVersion = platformVersion; | |
}); | |
} | |
requestPermission() async { | |
final res = await SimplePermissions.requestPermission(Permission.Camera); | |
} | |
checkPermission() async { | |
bool res = await SimplePermissions.checkPermission(Permission.Camera); | |
if (!res) { | |
setState(() { | |
_statusMessage = "waiting for camera permission"; | |
}); | |
} else { | |
setState(() { | |
_statusMessage = "camera permission has been granted"; | |
}); | |
} | |
} | |
getPermissionStatus() async { | |
final res = await SimplePermissions.getPermissionStatus(Permission.Camera); | |
} | |
@override | |
void didChangeAppLifecycleState(AppLifecycleState state) { | |
checkPermission(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
backgroundColor: Colors.white, | |
appBar: AppBar( | |
title: Text("Test page 1"), | |
), | |
body: Center( | |
child: Text(_statusMessage), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment