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

A production-grade Flutter plugin for unified access to Bluetooth, NFC, USB, and native hardware features.

example/lib/main.dart

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

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

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _status = 'Idle';
  final _nativeDeviceKit = NativeDeviceKit.instance;

  @override
  void initState() {
    super.initState();
    // Listen to module events
    _nativeDeviceKit.bluetooth.eventStream.listen((event) {
      debugPrint('Bluetooth Event: $event');
      if (mounted) {
        setState(() {
          _status = 'Bluetooth: $event';
        });
      }
    });

    _nativeDeviceKit.nfc.eventStream.listen((event) {
      debugPrint('NFC Event: $event');
      if (mounted) {
        setState(() {
          _status = 'NFC: $event';
        });
      }
    });

    _nativeDeviceKit.usb.eventStream.listen((event) {
       debugPrint('USB Event: $event');
       if (mounted) {
         setState(() {
           _status = 'USB: $event';
         });
       }
    });
  }

  Future<void> _scanBluetooth() async {
    setState(() => _status = 'Starting Scan...');
    try {
      await _nativeDeviceKit.bluetooth.scan();
    } catch (e) {
      setState(() => _status = 'Error: $e');
    }
  }

  Future<void> _readNfc() async {
    setState(() => _status = 'Starting NFC Read...');
    try {
      await _nativeDeviceKit.nfc.readTag();
    } catch (e) {
      setState(() => _status = 'Error: $e');
    }
  }

  Future<void> _getUsbDevices() async {
     setState(() => _status = 'Getting USB Devices...');
     try {
       final devices = await _nativeDeviceKit.usb.getConnectedDevices();
       setState(() => _status = 'USB Devices: ${devices.length} found');
     } catch (e) {
       setState(() => _status = 'Error: $e');
     }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Native Device Kit'),
        ),
        body: Center(
          child: Padding(
            padding: const EdgeInsets.all(16.0),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text(
                  _status,
                  textAlign: TextAlign.center,
                  style: const TextStyle(fontWeight: FontWeight.bold),
                ),
                const SizedBox(height: 30),
                Wrap(
                  spacing: 10,
                  runSpacing: 10,
                  alignment: WrapAlignment.center,
                  children: [
                    ElevatedButton.icon(
                      onPressed: _scanBluetooth,
                      icon: const Icon(Icons.bluetooth),
                      label: const Text('Scan BLE'),
                    ),
                    ElevatedButton.icon(
                      onPressed: _readNfc,
                      icon: const Icon(Icons.nfc),
                      label: const Text('Read NFC'),
                    ),
                    ElevatedButton.icon(
                      onPressed: _getUsbDevices,
                      icon: const Icon(Icons.usb),
                      label: const Text('List USB'),
                    ),
                  ],
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
1
likes
155
points
0
downloads

Publisher

unverified uploader

Weekly Downloads

A production-grade Flutter plugin for unified access to Bluetooth, NFC, USB, and native hardware features.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on native_device_kit

Packages that implement native_device_kit