Friday, November 27, 2020

Biometric |Qr Code Scanner | OCR Reader | Text Scanner

.................................................................................................................................................................................................................................. 
Example  :#1 [ Biometric ]

Setup

Update the project's AndroidManifest.xml file to include the USE_FINGERPRINT permissions:

  <uses-permission android:name="android.permission.USE_FINGERPRINT"/>

FlutterFragmentActivity as opposed to FlutterActivity in the java or kt




Library
https://pub.dev/packages/local_auth/install
  local_auth: ^0.6.3+4

...........................................................................................................................................................................................................................................
Example :#1[Biometric ]
1.Code Here

Home.dart

import 'package:demo/auth.dart';
import 'package:flutter/material.dart';

class Home extends StatefulWidget {
  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Home'),
        actions: [
          IconButton(
              icon: Icon(Icons.exit_to_app),
              iconSize: 20,
              onPressed: () {
                Navigator.pushReplacement(context, MaterialPageRoute(
                  builder: (context) => Auth()
                  
                ));
              })
        ],
      ),
    );
  }
}
......................
Auth.dart

import 'package:demo/home.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:local_auth/local_auth.dart';

class Auth extends StatefulWidget {
  @override
  _AuthState createState() => _AuthState();
}

class _AuthState extends State<Auth> {
  LocalAuthentication localAuthentication = LocalAuthentication();
  bool _checkBio = false;
  bool _isBioFinger = false;

  @override
  void initState() {
    super.initState();
    _checkBioMetric();
    _listBioAndFindFingerType();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Auth'),
      ),
      body: Center(
        child: SingleChildScrollView(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              IconButton(
                  icon: Icon(
                    Icons.fingerprint,
                  ),
                  iconSize: 100,
                  onPressed: startAuth)
            ],
          ),
        ),
      ),
    );
  }

  void _checkBioMetric() async {
    try {
      final bio = await localAuthentication.canCheckBiometrics;
      setState(() {
        _checkBio = bio;
      });
      print(' BioMetric = $_checkBio');
    } catch (e) {}
  }

  void _listBioAndFindFingerType() async {
    List<BiometricType> listType;

    try {
      listType = await localAuthentication.getAvailableBiometrics();
    } on PlatformException catch (e) {
      print(e.message);
    }
    print('list =$listType');
    if (listType.contains(BiometricType.fingerprint)) {
      setState(() {
        _isBioFinger = true;
      });
      print('FingerPrint is $_isBioFinger');
    }
  }

  void startAuth() async {
    bool _isAuthenticated =false;
    try {
      _isAuthenticated = await localAuthentication.authenticateWithBiometrics(
        localizedReason: 'Scan your fingerprint',
        useErrorDialogs: true,
        stickyAuth: true,
        // androidAuthStrings: null,
        // iOSAuthStrings: null
      );
    } on PlatformException catch (e) {
      print(e.message);
    }
    if (_isAuthenticated) {
      Navigator.pushReplacement(
          context, MaterialPageRoute(builder: (c) => Home()));
    }
  }
}

...............................
main.dart
import 'package:demo/auth.dart';
import 'package:flutter/material.dart';


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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Auth(),
      
    );
  }
}






2.


3.


4.

5.
6.


7.


8.


9.
10.



11.




Test


...........................................................................................................................................................................................................................................
Example :#1.2 [ Fingerprint / Face unlock local authentication using flutter]

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Home(),
    );
  }
}

class Home extends StatefulWidget {
  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  LocalAuthentication localAuthentication = LocalAuthentication();
  bool canAuth = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Local Auth'),
      ),
      body: Center(
        child: Column(
          children: [
            RaisedButton(
                child: Text('Check'),
                onPressed: () async {
                  canAuth = await localAuthentication.canCheckBiometrics;
                  print(canAuth.toString());
                }),
            RaisedButton(
                child: Text('Verify'),
                onPressed: () async {
                  List<BiometricType> list = List();
                  try {
                    if (canAuth) {
                      list = await localAuthentication.getAvailableBiometrics();
                      if (list.length > 0) {
                        bool result =
                            await localAuthentication.authenticateWithBiometrics(
                                localizedReason:
                                    'Please Enter your FingerPrint to unlock',
                                useErrorDialogs: true,
                                stickyAuth: true);
                        print('result is ${result}');
                        if (list.contains(BiometricType.fingerprint)) {
                          print('Fingerprint');
                        }
                        if (list.contains(BiometricType.iris)) {
                          print('iris');
                        }
                        if (list.contains(BiometricType.face)) {
                          print('Face unlock');
                        }
                      }
                    }
                  } catch (e) {}
                })
          ],
        ),
      ),
    );
  }
}


Happy Coding :)
...........................................................................................................................................................................................................................................
Example :#2 [Qr Code Scanner]

Library
https://pub.dev/packages/qr_code_scanner/install
  qr_code_scanner: ^0.0.13

min 24
..............................
Code Here






Happy Coding :)
...........................................................................................................................................................................................................................................
Example :#3[ Flutter: OCR Reader | Text Scanner]

Library
https://pub.dev/packages/flutter_mobile_vision
  flutter_mobile_vision: ^0.1.4+1
.............................
AndroidManifest.xml

         <uses-permission android:name="android.permission.CAMERA" />
         <uses-feature android:name="android.hardware.camera" />

<activity android:name="io.github.edufolly.fluttermobilevision.barcode.BarcodeCaptureActivity" />

..............................
Code Here
import 'package:flutter/material.dart';
import 'package:flutter_mobile_vision/flutter_mobile_vision.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Home(),
    );
  }
}

class Home extends StatefulWidget {
  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  bool isInitilized = false;
  @override
  void initState() {
    FlutterMobileVision.start().then((value) {
      isInitilized = true;
    });
    super.initState();
  }

  _startScan() async {
    List<OcrText> list = List();
    try {
      FlutterMobileVision.read(
        waitTap: true,
        fps: 5,
        multiple: true
      );
      for(OcrText text in list){
        print('value is ${text.value}');
      }
    } catch (e) {}
  }

  @override

  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('OCR Reader | Text Scanner App'),
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.camera_alt),
        onPressed:()=> _startScan(),
      ),
    );
  }
}

Happy Coding :)
...........................................................................................................................................................................................................................................
Example :#4


No comments:

Post a Comment