native_haptics_and_audio 1.0.0 copy "native_haptics_and_audio: ^1.0.0" to clipboard
native_haptics_and_audio: ^1.0.0 copied to clipboard

A high-performance Flutter plugin delivering ultra-low latency audio and haptic feedback for POS barcode scanners. By bypassing heavy audio packages and leveraging native hardware APIs with pre-bundle [...]

example/lib/main.dart

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

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

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

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

class _MyAppState extends State<MyApp> {
  final _repo = NativeHapticsAndAudioRepository.instance;
  bool _ready = false;
  String? _error;

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

  Future<void> _init() async {
    await _repo.initialize();
    if (!mounted) return;
    setState(() {
      _ready = _repo.isInitialized;
      _error = _ready ? null : 'Initialization failed — check logs.';
    });
  }

  @override
  void dispose() {
    _repo.release();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.dark(useMaterial3: true),
      home: Scaffold(
        appBar: AppBar(title: const Text('Haptics & Audio Demo')),
        body: _ready
            ? _buildButtons()
            : Center(
                child: _error != null ? Text(_error!, style: const TextStyle(color: Colors.red)) : const CircularProgressIndicator(),
              ),
      ),
    );
  }

  Widget _buildButtons() {
    return ListView(
      padding: const EdgeInsets.all(24),
      children: [
        const Text('Sounds', style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
        const SizedBox(height: 12),
        _soundButton('Scanner Beep', PosSound.scannerBeep),
        _soundButton('Warning Beep', PosSound.warningBeep),
        _soundButton('Double Warning', PosSound.doubleWarningBeep),
        _soundButton('Ka-Ching', PosSound.kaching),
        const SizedBox(height: 32),
        const Text('Haptics', style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
        const SizedBox(height: 12),
        _hapticButton('Success', PosHaptic.success),
        _hapticButton('Warning', PosHaptic.warning),
        _hapticButton('Error', PosHaptic.error),
      ],
    );
  }

  Widget _soundButton(String label, PosSound sound) {
    return Padding(
      padding: const EdgeInsets.only(bottom: 8),
      child: FilledButton.icon(onPressed: () => _repo.playSound(sound), icon: const Icon(Icons.volume_up), label: Text(label)),
    );
  }

  Widget _hapticButton(String label, PosHaptic haptic) {
    return Padding(
      padding: const EdgeInsets.only(bottom: 8),
      child: FilledButton.tonalIcon(onPressed: () => _repo.playHaptic(haptic), icon: const Icon(Icons.vibration), label: Text(label)),
    );
  }
}
3
likes
140
points
104
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A high-performance Flutter plugin delivering ultra-low latency audio and haptic feedback for POS barcode scanners. By bypassing heavy audio packages and leveraging native hardware APIs with pre-bundled uncompressed sounds, it guarantees instant, zero-lag physical and auditory responses on Android and iOS.

Repository (GitHub)
View/report issues

Topics

#haptics #audio #pos #barcode-scanner #native

License

MIT (license)

Dependencies

flutter, meta

More

Packages that depend on native_haptics_and_audio

Packages that implement native_haptics_and_audio