simple_native 0.0.14 copy "simple_native: ^0.0.14" to clipboard
simple_native: ^0.0.14 copied to clipboard

A comprehensive Flutter plugin for accessing native device features including Camera (Photos, QR & Barcode), Location, Device Information, and Biometric Authentication.

simple_native #

A comprehensive Flutter plugin for accessing native device features including Camera, Location, Device Information, and Biometric Authentication.

Features #

  • Camera:
    • Display a camera preview using SimpleCameraView.
    • Capture images.
    • Support for real-time image streaming (e.g., for image processing).
    • Configurable camera types (Image, QR Code, Stream).
    • Barcode & QR Scanning: Scan various barcode formats alongside QR codes.
    • Selectable Camera Position: Choose between front or back camera on initialization.
    • Locked Portrait Orientation: The camera view is locked to portrait mode to ensure consistent preview orientation.
    • Image Conversion: Built-in support for converting camera images (NV21/BGRA8888) to BMP format for display via SimpleCameraImage.toImage().
  • Location:
    • Get the current device location (latitude, longitude).
  • Device Information:
    • Retrieve basic device information (OS version, device model, etc.).
  • Biometric Authentication:
    • Authenticate users using fingerprint, face recognition, or iris scanner.
    • Handle various authentication states (success, failure, not supported).
    • Customizable title and cancel button text.
    • Check available biometric types (Face, Fingerprint, Iris).
    • Open Biometric Settings: Directly open the system's biometric settings page to allow users to enroll or manage their biometrics.
  • Platform Version:
    • Get the current platform version.

Getting Started #

Add simple_native as a dependency in your pubspec.yaml file.

dependencies:
  simple_native: ^0.0.13

Usage #

1. Camera #

Use SimpleCameraView to display the camera preview.

import 'package:simple_native/simple_native.dart';

// ...

SimpleCameraController? _controller;

SimpleCameraView(
  cameraType: SimpleCameraType.image, // or SimpleCameraType.qr, SimpleCameraType.stream
  cameraPosition: SimpleCameraPosition.back, // or SimpleCameraPosition.front
  onCameraCreated: (controller) {
    _controller = controller;
    
    // Example: Listen to image stream if cameraType is stream
    // controller.onImageStream((image) {
    //   print("Received image frame: ${image.width}x${image.height}");
    //   
    //   // Convert to BMP for display if needed
    //   // final bmpBytes = image.toImage();
    // });
  },
  onResult: (result) {
    // Handle camera result (e.g., QR code or Barcode value)
    if (result.type == SimpleCameraResultType.qr) {
        print("QR Code: ${result.value}");
    } else if (result.type == SimpleCameraResultType.barcode) {
        print("Barcode: ${result.value}");
    }
  },
)

// ...

// To take a picture:
// final String? imagePath = await _controller?.takePicture();
// if (imagePath != null) {
//   print("Image captured at: $imagePath");
// }

// To switch camera:
// await _controller?.switchCamera();

// To resume scanning (after a QR code is detected):
// await _controller?.resumeScanning();

2. Location #

Get the current location.

import 'package:simple_native/simple_native.dart';

// ...

final simpleNative = SimpleNative();
final location = await simpleNative.getCurrentLocation();

if (location != null) {
  print("Latitude: ${location.latitude}, Longitude: ${location.longitude}");
}

3. Device Information #

Get device information.

import 'package:simple_native/simple_native.dart';

// ...

final simpleNative = SimpleNative();
final deviceInfo = await simpleNative.getDeviceInfo();

if (deviceInfo != null) {
  print("Device: ${deviceInfo.model}, OS: ${deviceInfo.osVersion}");
}

4. Biometric Authentication #

Authenticate using biometrics.

import 'package:simple_native/simple_native.dart';

// ...

final simpleNative = SimpleNative();

// 1. Check what type of biometrics the device supports
final biometricType = await simpleNative.getAvailableBiometric();

if (biometricType != SimpleBiometricType.notSupported) {
    print("Device supports: $biometricType");
    
    // 2. Authenticate
    final result = await simpleNative.authenticate(
      localizedReason: "Please authenticate to continue",
      title: "Biometric Login", // Optional, default: "Biometric Authentication"
      cancelButtonText: "Cancel", // Optional, default: "Cancel"
    );

    switch (result) {
      case SimpleBiometricState.success:
        print("Authentication successful");
        break;
      case SimpleBiometricState.notSupported:
        print("Biometrics not supported or not enrolled");
        // You might want to open settings here
        break;
      case SimpleBiometricState.failure:
        print("Authentication failed or cancelled by user");
        break;
      default:
        break;
    }
} else {
    print("Device does not support biometrics");
}

// 3. Open Biometric Settings (e.g., if user hasn't enrolled yet)
// await simpleNative.openBiometricSettings();

Platform Support #

Feature Android iOS
Camera
Location
Device Info
Biometric Auth

Installation #

Ensure you have the necessary permissions configured in your Android and iOS projects.

Android (AndroidManifest.xml):

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
<uses-permission android:name="android.permission.USE_FINGERPRINT" />

Note: For biometric authentication on older Android versions (API < 28), your app's MainActivity used to require extending FlutterFragmentActivity. This plugin now supports standard FlutterActivity across all supported Android versions.

iOS (Info.plist):

<key>NSCameraUsageDescription</key>
<string>Need camera access to take pictures.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Need location access to show current location.</string>
<key>NSFaceIDUsageDescription</key>
<string>Need Face ID access to authenticate.</string>

License #

This project is licensed under the BSD 3-Clause License - see the LICENSE file for details.

3
likes
130
points
250
downloads

Documentation

API reference

Publisher

verified publishertranduc1710.com

Weekly Downloads

A comprehensive Flutter plugin for accessing native device features including Camera (Photos, QR & Barcode), Location, Device Information, and Biometric Authentication.

Homepage

Topics

#camera #location #device-info #native #plugin

License

BSD-3-Clause (license)

Dependencies

flutter, flutter_web_plugins, plugin_platform_interface

More

Packages that depend on simple_native

Packages that implement simple_native