test_scan_barcode 1.0.1 copy "test_scan_barcode: ^1.0.1" to clipboard
test_scan_barcode: ^1.0.1 copied to clipboard

PlatformAndroidiOS
outdated

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}");
  }
}
0
likes
120
points
7
downloads

Publisher

unverified uploader

Weekly Downloads

Sample flutter plugin

Homepage

Documentation

API reference

License

unknown (license)

Dependencies

core_scan, flutter, plugin_platform_interface

More

Packages that depend on test_scan_barcode

Packages that implement test_scan_barcode