test_scan_barcode 1.0.1
test_scan_barcode: ^1.0.1 copied to clipboard
Sample flutter plugin
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:test_scan_barcode/barcode_capture.dart';
import 'package:test_scan_barcode/models/batch_scan_result.dart';
import 'package:test_scan_barcode/models/one_of_many_result.dart';
import 'package:test_scan_barcode/models/scan_result_success.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> implements BarcodeScanResultCallback {
String? licenseKey = "2acf14c1f0596bf1ba74d88a0ae011744eca5dad";
bool _isPermissionMessageVisible = false;
@override
void initState() {
super.initState();
checkPermission();
}
@override
Widget build(BuildContext context) {
BarcodeScanResultCallbackHandler callbackHandler =
BarcodeScanResultCallbackHandler();
// Register this widget as the callback
callbackHandler.registerCallback(this);
return MaterialApp(
home: Scaffold(
body: Stack(
children: [
BarcodeCapture(
licenseKey: licenseKey,
scanType: BarcodeScanType.oneOfMany.name,
barcodeScanResultBackHandler: callbackHandler,
),
/*IconButton(
onPressed: () {
setState(() {
print("onpressed called");
});
},
icon: const Icon(Icons.light, color: Colors.white)),*/
],
)),
);
}
void checkPermission() {
Permission.camera.request().isGranted.then((value) => setState(() {
_isPermissionMessageVisible = !value;
if (value) {
//permission granted
} else {
Fluttertoast.showToast(
msg: "Permission required",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 1,
backgroundColor: Colors.white,
textColor: Colors.black,
fontSize: 16.0);
}
}));
}
@override
void onScanResultSuccess(ScanResultSuccess scanResultSuccess) {
print("value of scan result success ${scanResultSuccess.modelScanType}");
}
@override
void oneOfManyResult(List<OneOfManyResult> oneOfManyResult) {
print("value of scan result success ${oneOfManyResult.length}");
for (var value in oneOfManyResult) {
print("value of one of many ${value.decodedFormat}");
print("value of one of many ${value.decodedValue}");
print("******************************************");
}
}
@override
void batchScanResult(List<BatchScanResult> oneOfManyResult) {
print("batchScanResult success ${oneOfManyResult.length}");
}
}