awesome_mobile_scanner 0.0.4 copy "awesome_mobile_scanner: ^0.0.4" to clipboard
awesome_mobile_scanner: ^0.0.4 copied to clipboard

A universal Flutter barcode and QR code scanner using CameraX/ML Kit for Android, AVFoundation/Apple Vision for iOS & macOS, and ZXing for web.

example/lib/main.dart

import 'package:awesome_mobile_scanner/awesome_mobile_scanner.dart';
import 'package:awesome_mobile_scanner_example/screens/credit_card_scanner_example.dart';
import 'package:awesome_mobile_scanner_example/screens/mobile_scanner_advanced.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MaterialApp(title: 'Mobile Scanner Example', home: _ExampleHome()));
}

/// Implementation of Mobile Scanner example with simple configuration
class MobileScannerSimple extends StatefulWidget {
  /// Constructor for simple Mobile Scanner example
  const MobileScannerSimple({super.key});

  @override
  State<MobileScannerSimple> createState() => _MobileScannerSimpleState();
}

class _MobileScannerSimpleState extends State<MobileScannerSimple> {
  Barcode? _barcode;

  Widget _barcodePreview(Barcode? value) {
    if (value == null) {
      return const Text('Scan something!', overflow: TextOverflow.fade, style: TextStyle(color: Colors.white));
    }

    return Text(
      value.displayValue ?? 'No display value.',
      overflow: TextOverflow.fade,
      style: const TextStyle(color: Colors.white),
    );
  }

  void _handleBarcode(BarcodeCapture barcodes) {
    if (mounted) {
      setState(() {
        _barcode = barcodes.barcodes.firstOrNull;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Simple Mobile Scanner')),
      backgroundColor: Colors.black,
      body: Stack(
        children: [
          MobileScanner(onDetect: _handleBarcode),
          Align(
            alignment: Alignment.bottomCenter,
            child: Container(
              alignment: Alignment.bottomCenter,
              height: 100,
              color: const Color.fromRGBO(0, 0, 0, 0.4),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [Expanded(child: Center(child: _barcodePreview(_barcode)))],
              ),
            ),
          ),
        ],
      ),
    );
  }
}

/// Homepage for example app with selection between basic and advanced screen.
class _ExampleHome extends StatelessWidget {
  const _ExampleHome();

  Widget _buildItem(BuildContext context, String label, String subtitle, Widget page, IconData icon) {
    return GestureDetector(
      onTap: () {
        Navigator.of(context).push(MaterialPageRoute<void>(builder: (context) => page));
      },
      child: Card(
        elevation: 5,
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
        margin: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
        child: Padding(
          padding: const EdgeInsets.all(16),
          child: Row(
            children: [
              Icon(icon, size: 40, color: Colors.blueAccent),
              const SizedBox(width: 20),
              Expanded(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(label, style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w600)),
                    const SizedBox(height: 5),
                    Text(subtitle, style: const TextStyle(fontSize: 14, color: Colors.grey)),
                  ],
                ),
              ),
              const Icon(Icons.arrow_forward_ios, color: Colors.grey),
            ],
          ),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Mobile Scanner Example', style: TextStyle(fontWeight: FontWeight.bold)),
        centerTitle: true,
        backgroundColor: Colors.blueAccent,
        elevation: 0,
      ),
      body: Container(
        decoration: const BoxDecoration(
          gradient: LinearGradient(
            colors: [Colors.blueAccent, Colors.lightBlue],
            begin: Alignment.topCenter,
            end: Alignment.bottomCenter,
          ),
        ),
        child: Center(
          child: ListView(
            physics: const BouncingScrollPhysics(),
            children: [
              const SizedBox(height: 20),
              _buildItem(
                context,
                'Simple Mobile Scanner',
                'Example of a simple mobile scanner instance without defining '
                    'a controller.',
                const MobileScannerSimple(),
                Icons.qr_code_scanner,
              ),
              _buildItem(
                context,
                'Advanced Mobile Scanner',
                'Example of an advanced mobile scanner instance with a '
                    'controller, and multiple control widgets.',
                const MobileScannerAdvanced(),
                Icons.settings_remote,
              ),
              _buildItem(
                context,
                'Credit Card Scanner',
                'Example of a credit card scanner using OCR to detect '
                    'card numbers, expiry dates, and cardholder names.',
                const CreditCardScannerExample(),
                Icons.credit_card,
              ),
              const SizedBox(height: 20),
            ],
          ),
        ),
      ),
    );
  }
}
0
likes
145
points
53
downloads
screenshot

Publisher

verified publisherflutterwithakmaljon.uz

Weekly Downloads

A universal Flutter barcode and QR code scanner using CameraX/ML Kit for Android, AVFoundation/Apple Vision for iOS & macOS, and ZXing for web.

Repository (GitHub)

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

collection, flutter, flutter_web_plugins, meta, plugin_platform_interface, web

More

Packages that depend on awesome_mobile_scanner

Packages that implement awesome_mobile_scanner