nativeconnect 0.0.2 copy "nativeconnect: ^0.0.2" to clipboard
nativeconnect: ^0.0.2 copied to clipboard

The most intuitive Flutter package for seamless native feature integration.

šŸš€ NativeConnect #

pub package License: MIT Flutter Style

The most intuitive, production-grade Flutter package for seamless native device hardware integration. Interact with Location (GPS), Camera, and Sensors using a unified, robust one-line static API with automatic permission checks and lifecycle-safe stream handlers.


šŸŽÆ Why NativeConnect? #

Feature The Hard Way (Normal Packages) The Smart Way (NativeConnect)
Boilerplate 30+ lines of permission checks, try-catches & redirects 1 Line of code
Permissions Manual request loops & setting handling Auto-managed on-demand
Battery Life Stream leaks & background drains if forgot to dispose Lifecycle-safe auto-pausing
Error Handling Raw platform-specific codes that crash apps Standardized exceptions

✨ Key Features #

  • šŸ“¦ Unified Architecture: Access Location, Camera, and Sensors with a single import import 'package:nativeconnect/nativeconnect.dart';. No underlying library imports required.
  • šŸ›”ļø On-The-Fly Permissions: Automatically checks and requests system permissions only when the feature is called. Zero upfront permission spamming.
  • šŸ“” Intelligent GPS Location: Verifies if global location services are enabled on the device. Gracefully handles disabled GPS and coarse/fine accuracy levels.
  • šŸ“ø Smart Camera & Compression: Select front/rear camera and apply on-the-fly photo compression (imageQuality, maxWidth, maxHeight) to prevent memory overload.
  • šŸŒ€ Battery-Friendly Sensors: Streams 3D gravity accelerometer values with an auto-cancelling listener that turns off when the app goes into the background, preventing device lag and preserving battery.
  • āš ļø Custom Exception Mapping: Exposes a clean NativeConnectException with clear error codes like LOCATION_SERVICE_DISABLED or CAMERA_PERMISSION_DENIED.

šŸš€ Installation & Setup #

1. Add Dependency #

Add nativeconnect to your pubspec.yaml dependencies:

dependencies:
  nativeconnect: ^0.0.1

2. Platform Permissions Configuration #

šŸ¤– Android Setup

Insert the following permissions inside your android/app/src/main/AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Camera Access -->
    <uses-permission android:name="android.permission.CAMERA" />
    
    <!-- GPS Location Access -->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
</manifest>

šŸ iOS Setup

Add the following keys to your ios/Runner/Info.plist:

<key>NSCameraUsageDescription</key>
<string>This app requires camera access to capture photographs.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>This app requires location access to retrieve physical coordinates.</string>

šŸ’» Code Examples #

1. Fetch Current GPS Location #

import 'package:nativeconnect/nativeconnect.dart';

Future<void> fetchLocation() async {
  try {
    final position = await NativeConnect.getLocation(
      accuracy: LocationAccuracy.high, // Customizable accuracy level
    );
    if (position != null) {
      print('Latitude: ${position.latitude}, Longitude: ${position.longitude}');
    }
  } on NativeConnectException catch (e) {
    print('Location Error [${e.code}]: ${e.message}');
  }
}

2. Capture a Photo (with dynamic compression) #

import 'package:nativeconnect/nativeconnect.dart';

Future<void> captureImage() async {
  try {
    final XFile? photo = await NativeConnect.takePhoto(
      imageQuality: 85, // Compresses image to 85% to save bandwidth & storage
      preferredCameraDevice: CameraDevice.rear,
    );
    if (photo != null) {
      print('Photo saved successfully: ${photo.path}');
    }
  } on NativeConnectException catch (e) {
    print('Camera Error [${e.code}]: ${e.message}');
  }
}

3. Stream Real-Time Gravity Sensors #

import 'package:nativeconnect/nativeconnect.dart';

void watchMovement() {
  NativeConnect.watchGravity(
    samplingPeriod: SensorInterval.normalInterval, // Battery-optimized sampling
  ).listen((GravityData data) {
    print('X Axis Force: ${data.x} m/s²');
    print('Y Axis Force: ${data.y} m/s²');
    print('Z Axis Force: ${data.z} m/s²');
    print('Total Magnitude: ${data.magnitude} m/s²');
  }, onError: (error) {
    print('Sensor Stream Error: $error');
  });
}

āœļø Author & Creator #

Created with ā¤ļø by Anit

A passionate software developer dedicated to crafting clean, premium, and hyper-efficient developer utilities.


šŸ›”ļø License #

This project is licensed under the MIT License - see the LICENSE file for details.

1
likes
0
points
183
downloads

Publisher

unverified uploader

Weekly Downloads

The most intuitive Flutter package for seamless native feature integration.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

device_info_plus, flutter, geolocator, image_picker, permission_handler, sensors_plus, share_plus

More

Packages that depend on nativeconnect