scanning_gun 0.0.1+2 copy "scanning_gun: ^0.0.1+2" to clipboard
scanning_gun: ^0.0.1+2 copied to clipboard

This is an unofficial FlutterPlugin to connect flutter code with a Scanning_Gun from Hopeland.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:scanning_gun/scanning_gun.dart';

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

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scanner(),
    );
  }
}

class Scanner extends StatefulWidget {
  const Scanner({Key? key}) : super(key: key);

  @override
  _ScannerState createState() => _ScannerState();
}

class _ScannerState extends State<Scanner> {
  ScanningGun scannerGun = ScanningGun();
  FocusNode focusNode = FocusNode();
  var scannerResponse = "";

  @override
  void initState(){
    super.initState();
    setState(() {
      scannerGun.initialize();
    });
  }
  @override
  Widget build(BuildContext context) {
    FocusScope.of(context).requestFocus(focusNode);
    return Scaffold(
      body: RawKeyboardListener(
        autofocus: true,
        focusNode: focusNode,   // <-- more magic
        onKey: (RawKeyEvent event) {

          //The method is to scan by clicking on the button in the scanner gun,
          // you can detect the button in Logicalkeyboardkey.f10
          if (event.data.logicalKey == LogicalKeyboardKey.f10) {
            scannerGun.scan().then((value){
              showDialog(context: context, builder: (context){
                return AlertDialog(
                  content: Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Text(
                        "Scanner Gun Response".toUpperCase(),
                        style: const TextStyle(
                          fontWeight: FontWeight.bold,
                          fontSize: 18,
                        ),
                      ),
                      Text(value,
                        style: const TextStyle(
                          fontWeight: FontWeight.bold,
                          fontSize: 18,
                        ),
                      ),
                    ],
                  ),
                );
              });
            });
          }
        },
        child: SizedBox(
          width: MediaQuery.of(context).size.width,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(
                "Scanner Gun Example".toUpperCase(),
                style: const TextStyle(
                  fontWeight: FontWeight.bold,
                  fontSize: 18,
                ),
              ),
              TextButton(
                onPressed: () {
                  setState(() {
                    scannerGun.scan().then((value){
                      showDialog(context: context, builder: (context){
                        return AlertDialog(
                          content: Column(
                            crossAxisAlignment: CrossAxisAlignment.center,
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              Text(
                                "Scanner Gun Response".toUpperCase(),
                                style: const TextStyle(
                                  fontWeight: FontWeight.bold,
                                  fontSize: 18,
                                ),
                              ),
                              Text(value,
                                style: const TextStyle(
                                  fontWeight: FontWeight.bold,
                                  fontSize: 18,
                                ),
                              ),
                            ],
                          ),
                        );
                      });
                    });
                  });
                },
                child: const Text("Scan"),
              )
            ],
          ),
        ),
      ),
    );
  }
}
0
likes
120
pub points
11%
popularity

Publisher

unverified uploader

This is an unofficial FlutterPlugin to connect flutter code with a Scanning_Gun from Hopeland.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on scanning_gun