Guest User

Bla

a guest
Aug 19th, 2019
86
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import 'package:flutter/material.dart';
  2. import 'package:simple_permissions/simple_permissions.dart';
  3.  
  4. void main() => runApp(MyApp());
  5.  
  6. class MyApp extends StatelessWidget {
  7. // This widget is the root of your application.
  8. @override
  9. Widget build(BuildContext context) {
  10. return MaterialApp(
  11. title: 'Flutter Demo',
  12. theme: ThemeData(
  13. primarySwatch: Colors.blue,
  14. ),
  15. home: MyHomePage(title: 'Flutter Demo Home Page'),
  16. );
  17. }
  18. }
  19.  
  20. class MyHomePage extends StatefulWidget {
  21. MyHomePage({Key key, this.title}) : super(key: key);
  22.  
  23.  
  24. final String title;
  25.  
  26. @override
  27. _MyHomePageState createState() => _MyHomePageState();
  28. }
  29.  
  30. class _MyHomePageState extends State<MyHomePage> {
  31.  
  32. var _data = "Scan";
  33.  
  34. //Fungsi Untuk Check Permission Camera -> Scan QR
  35. void scanQr() async {
  36. bool isAllowed = await SimplePermissions.checkPermission(Permission.Camera);
  37. PermissionStatus status = PermissionStatus.notDetermined;
  38. if (isAllowed) {
  39. print("Di izinkan");
  40. }
  41. requestPermission();
  42. }
  43.  
  44. requestPermission() async {
  45. final res = await SimplePermissions.requestPermission(Permission.Camera);
  46. print("permission request result is " + res.toString());
  47. }
  48.  
  49.  
  50. @override
  51. Widget build(BuildContext context) {
  52. return Scaffold(
  53. backgroundColor: Colors.white,
  54. body: Center(
  55. child: GestureDetector(
  56. onTap: (){
  57. scanQr();
  58. },
  59. child: Container(
  60. width: 150.0,
  61. height: 50.0,
  62. decoration: BoxDecoration(
  63. color: Colors.greenAccent[400]
  64. ),
  65. child: Center(
  66. child: Text(_data, style: TextStyle(color: Colors.white),),
  67. ),
  68. ),
  69. ),
  70. ),
  71. );
  72. }
  73. }
RAW Paste Data