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

outdated

A plugin for barcode scanning support on Android and iOS. Supports barcodes, QR codes, etc.

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:flutter_barcode_scanner/flutter_barcode_scanner.dart';

void main() => runApp(MyApp());

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

class _MyAppState extends State<MyApp> {
  String _scanBarcode = 'Unknown';

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String barcodeScanRes;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      barcodeScanRes = await FlutterBarcodeScanner.scanBarcode("#ff6666");
    } on PlatformException {
      barcodeScanRes = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _scanBarcode = barcodeScanRes;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Barcode scan'),
        ),
        body: Builder(builder: (BuildContext context) {
          return Container(
            alignment: Alignment.center,
            child: Flex(
                direction: Axis.vertical,
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  RaisedButton(
                    onPressed: () {
                      initPlatformState();
                    },
                    child: Text("Start barcode scan"),
                  ),
                  Text(
                    'Scan result : $_scanBarcode\n',
                    style: TextStyle(fontSize: 20),
                  ),
                ]),
          );
        }),
      ),
    );
  }
}
1282
likes
0
pub points
99%
popularity

Publisher

unverified uploader

A plugin for barcode scanning support on Android and iOS. Supports barcodes, QR codes, etc.

Homepage

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on flutter_barcode_scanner