mrzflutterplugin 1.0.8 copy "mrzflutterplugin: ^1.0.8" to clipboard
mrzflutterplugin: ^1.0.8 copied to clipboard

MRZ Scanner reads all MRZ on traveling documents following the ICAO 9303 Specification on Passports (2 – lines); MRV-B Visas (2 - lines); and ID cards (3 – lines).

example/lib/main.dart

import 'dart:async';
import 'dart:convert';
import 'dart:io' show Platform;

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:mrzflutterplugin/mrzflutterplugin.dart';

void main() {
  runApp(new MaterialApp(home: new MyPage()));
}

class MyPage extends StatefulWidget {
  @override
  _MyPageState createState() => new _MyPageState();
}

class _MyPageState extends State<MyPage> {
  String _result = 'No result yet';
  String fullImage;

  @override
  void initState() {
    super.initState();

    if (Platform.isAndroid) {
      Mrzflutterplugin.registerWithLicenceKey("android_licence_key");
    } else if (Platform.isIOS) {
      Mrzflutterplugin.registerWithLicenceKey("ios_licence_key");
    }
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> startScanning() async {
    String scannerResult;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      Mrzflutterplugin.setIDActive(true);
      Mrzflutterplugin.setPassportActive(true);
      Mrzflutterplugin.setVisaActive(true);
      Mrzflutterplugin.setVibrateOnSuccessfulScan(true);

      String jsonResultString = await Mrzflutterplugin.startScanner;

      Map<String, dynamic> jsonResult = jsonDecode(jsonResultString);
      fullImage = jsonResult['full_image'];

      scannerResult = jsonResult['document_number'] +
          ' ' +
          jsonResult['given_names_readable'] +
          ' ' +
          jsonResult['surname'];
    } on PlatformException catch (ex) {
      String message = ex.message;
      scannerResult = 'Scanning failed: $message';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _result = scannerResult;
    });
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future startContinuousScanning(BuildContext context) async {
    Mrzflutterplugin.setIDActive(true);
    Mrzflutterplugin.setPassportActive(true);
    Mrzflutterplugin.setVisaActive(true);
    Mrzflutterplugin.setVibrateOnSuccessfulScan(true);

    MRZScannerCallback callback = (result) {
      if (!result.startsWith("Error")) {
        Map<String, dynamic> jsonResult = jsonDecode(result);
        fullImage = jsonResult['full_image'];

        // If the widget was removed from the tree while the asynchronous platform
        // message was in flight, we want to discard the reply rather than calling
        // setState to update our non-existent appearance.
        if (!mounted) return;

        debugPrint("Successful scan: $result");
      }
    };

    Mrzflutterplugin.startContinuousScanner(callback, true);
  }

  @override
  Widget build(BuildContext buildContext) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Plugin example app'),
      ),
      body: new Center(
        child: new Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            if (fullImage != null) Image.memory(base64Decode(fullImage)),
            new TextButton(
              child: Text("Start Scanner"),
              onPressed: startScanning,
            ),
            new TextButton(
              child: Text("Start Continuous Scanner"),
              onPressed: () => startContinuousScanning(context),
            ),
            Padding(
              padding: const EdgeInsets.all(16.0),
              child: Text('Result: $_result'),
            ),
          ],
        ),
      ),
    );
  }
}
4
likes
40
pub points
38%
popularity

Publisher

unverified uploader

MRZ Scanner reads all MRZ on traveling documents following the ICAO 9303 Specification on Passports (2 – lines); MRV-B Visas (2 - lines); and ID cards (3 – lines).

Homepage

License

BSD-3-Clause (LICENSE)

Dependencies

flutter

More

Packages that depend on mrzflutterplugin