camcode 2.1.0 copy "camcode: ^2.1.0" to clipboard
camcode: ^2.1.0 copied to clipboard

outdated

A camera barcode scanner for Flutter Web using your favorite Javascript library

example/lib/main.dart

import 'package:camcode/cam_code_scanner.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(
    MaterialApp(
      routes: {
        '/': (context) => MyApp(),
      },
      initialRoute: '/',
    ),
  );
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String barcodeValue = 'Press button to scan a barcode';

  // Create a controller to send instructions to scanner
  final CamCodeScannerController _controller = CamCodeScannerController();

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
        floatingActionButton: FloatingActionButton(
          child: Icon(Icons.scanner),
          onPressed: () => openScanner(context, _onResult),
        ),
        appBar: AppBar(
          title: const Text('CamCode example app'),
        ),
        body: Center(
          child: Text(barcodeValue),
        ),
      ),
    );
  }

  void _onResult(String result) {
    setState(() {
      barcodeValue = result;
    });
  }

  void openScanner(BuildContext context, Function(String) onResult) {
    showDialog(
      context: context,
      builder: (context) => Stack(
        children: [
          CamCodeScanner(
            width: MediaQuery.of(context).size.width,
            height: MediaQuery.of(context).size.height,
            refreshDelayMillis: 200,
            onBarcodeResult: (barcode) {
              Navigator.of(context).pop();
              onResult(barcode);
            },
            controller: _controller,
            showDebugFrames: true,
          ),
          Positioned(
            bottom: 48.0,
            left: MediaQuery.of(context).size.width / 2,
            child: ElevatedButton(
              onPressed: () {
                _controller.releaseResources();
              },
              child: Text('Release resources'),
            ),
          ),
        ],
      ),
    );
  }
}
41
likes
0
pub points
62%
popularity

Publisher

verified publishermobile-tools.dev

A camera barcode scanner for Flutter Web using your favorite Javascript library

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, flutter_web_plugins, js

More

Packages that depend on camcode