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

PlatformAndroid

pda_scan_code

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:urovo_scan/urovo_scan.dart';
import 'package:flutter_broadcasts/flutter_broadcasts.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 _urovoScanPlugin = UrovoScan();
  String info = "";

  /// Scan Result Receiver
  BroadcastReceiver receiver = BroadcastReceiver(
    names: <String>["android.intent.ACTION_DECODE_DATA"], //Scanner Action
  );

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

  @override
  void dispose() {
    receiver.stop();
    super.dispose();
  }

  void initReceiver() {
    receiver.messages.listen(onScanResult);
    receiver.start();
  }

  void onScanResult(BroadcastMessage event) {
    var data = event.data;
    //Barcode Result:"barcode_string"
    //Barcode Type:"barcodeType"
    var result = data?['barcode_string'];
    var type = data?['barcodeType'];
    setState(() {
      info = "onScan:Result[$result],Type[$type]";
    });
  }

  void _startScan() async {
    setState(() {
      info = "_startScan";
    });
    bool? ret = await _urovoScanPlugin.startScan();
    setState(() {
      info = "_startScan:$ret";
    });
  }

  void _stopScan() async {
    setState(() {
      info = "_stopScan";
    });
    bool? ret = await _urovoScanPlugin.stopScan();
    setState(() {
      info = "_stopScan:$ret";
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Column(
          // Column is also a layout widget. It takes a list of children and
          // arranges them vertically. By default, it sizes itself to fit its
          // children horizontally, and tries to be as tall as its parent.
          //
          // Invoke "debug painting" (press "p" in the console, choose the
          // "Toggle Debug Paint" action from the Flutter Inspector in Android
          // Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
          // to see the wireframe for each widget.
          //
          // Column has various properties to control how it sizes itself and
          // how it positions its children. Here we use mainAxisAlignment to
          // center the children vertically; the main axis here is the vertical
          // axis because Columns are vertical (the cross axis would be
          // horizontal).
          // mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Wrap(spacing: 10, children: <Widget>[
              ElevatedButton(
                onPressed: _startScan,
                child: const Text("START_SCAN"),
              ),
              ElevatedButton(
                onPressed: _stopScan,
                child: const Text("STOP_SCAN"),
              ),
            ]),
            Row(
              children: <Widget>[Expanded(child: Text('INFO:$info'))],
            ),
          ],
        ),
      ),
    );
  }
}
2
likes
135
points
3
downloads

Publisher

unverified uploader

Weekly Downloads

pda_scan_code

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on pda_scan_code

Packages that implement pda_scan_code