Created
September 22, 2021 07:34
-
-
Save alamsyahh15/3cf93dba6856a8edaead637afa0fe563 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/material.dart'; | |
import 'package:flutter/cupertino.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:images_picker/images_picker.dart'; | |
import 'package:permission_handler/permission_handler.dart'; | |
import 'package:qrscan/qrscan.dart' as scanner; | |
class QrScanPage extends StatefulWidget { | |
const QrScanPage({Key key}) : super(key: key); | |
@override | |
_QrScanPageState createState() => _QrScanPageState(); | |
} | |
class _QrScanPageState extends State<QrScanPage> { | |
String code; | |
Future _scan() async { | |
await Permission.camera.request(); | |
String barcode = await scanner.scan(); | |
if (barcode == null) { | |
print('nothing return.'); | |
} else { | |
code = barcode; | |
} | |
setState(() {}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text("QR Scan Page"), | |
), | |
body: Center( | |
child: Text( | |
code ?? "Code Akan Muncul Disini", | |
style: TextStyle(fontWeight: FontWeight.bold), | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
child: Icon(Icons.qr_code), | |
onPressed: () => _scan(), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment