flutter_scankit 1.0.0 copy "flutter_scankit: ^1.0.0" to clipboard
flutter_scankit: ^1.0.0 copied to clipboard

outdated

A scan code Flutter plugin, which is a Flutter package for huawei scanning SDK.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:flutter_easy_permission/constants.dart';
import 'package:flutter_easy_permission/easy_permissions.dart';
import 'package:flutter_scankit/flutter_scankit.dart';



void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

const _permissions = const [
  Permissions.READ_EXTERNAL_STORAGE,
  Permissions.CAMERA
];

const _permissionGroup = const [
  PermissionGroup.Camera,
  PermissionGroup.Photos
];

class _MyAppState extends State<MyApp> {
  FlutterScankit scanKit;

  String code = "";

  @override
  void initState() {
    super.initState();
    scanKit = FlutterScankit();
    scanKit.addResultListen((val) {
      debugPrint("scanning result:$val");
      setState(() {
        code = val??"";
      });
    });

    FlutterEasyPermission().addPermissionCallback(
        onGranted: (requestCode, perms,perm) {
          startScan();
        },
        onDenied: (requestCode, perms,perm, isPermanent) {});
  }

  @override
  void dispose() {
    scanKit.dispose();
    super.dispose();
  }

  Future<void> startScan() async {
    try {
      await scanKit.startScan(scanTypes: [ScanTypes.ALL]);
    } on PlatformException {}
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              Text(code),
              SizedBox(height: 32,),
              ElevatedButton(
                child: Text("Scan code"),
                onPressed: () async {
                  if (!await FlutterEasyPermission.has(perms: _permissions,permsGroup: _permissionGroup)) {
                    FlutterEasyPermission.request(perms: _permissions,permsGroup: _permissionGroup);
                  } else {
                    startScan();
                  }
                },
              )
            ],
          ),
        ),
      ),
    );
  }
}
59
likes
0
points
781
downloads

Publisher

unverified uploader

Weekly Downloads

A scan code Flutter plugin, which is a Flutter package for huawei scanning SDK.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on flutter_scankit