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

outdated

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

flutter_scankit #

A scan code Flutter plugin, which is a Flutter package for HUAWEI Scan Kit SDK.

  • ✅ Android
  • ❌ iOS

Example #

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

import 'package:flutter/services.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 needPermissions = const [
  Permissions.READ_EXTERNAL_STORAGE,
  Permissions.CAMERA
];

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) {
          startScan();
        },
        onDenied: (requestCode, perms, isPermanentlyDenied) {});
  }

  @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("扫一扫"),
                onPressed: () async {
                  if (!await FlutterEasyPermission.has(needPermissions)) {
                    FlutterEasyPermission.request(needPermissions);
                  } else {
                    startScan();
                  }
                },
              )
            ],
          ),
        ),
      ),
    );
  }
}
59
likes
40
points
794
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

MIT (license)

Dependencies

flutter

More

Packages that depend on flutter_scankit