flutter_plugin_qr_scanner 0.0.1 copy "flutter_plugin_qr_scanner: ^0.0.1" to clipboard
flutter_plugin_qr_scanner: ^0.0.1 copied to clipboard

A qrcode scanner flutter plugin project. Support iOS, Android.

example/lib/main.dart

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

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

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

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

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

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initCodeState() async {
    String code;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      code = await QrScanner.scan(
        title: "scanner",
        laserColor: Colors.white, //default #ffff55ff
        playBeep: true, //default false
        promptMessage: "Point the QR code to the frame to complete the scan.",
        errorMsg: "Oops, something went wrong. You may need to check your permission of camera or restart the device.",
        permissionDeniedText: "Your privacy settings seem to prevent us from accessing your camera for barcode scanning. You can fix it by doing this, touch the OK button below to open the Settings and then turn the Camera on.",
        messageConfirmText: "OK",
        messageCancelText: "Cancel",
      );
    } on PlatformException {
      code = 'Failed to get qr code.';
    }

    // 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(() {
      _code = code;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text('qrcode: $_code\n'),
              OutlineButton(
                child: Text('Start Scan'),
                onPressed: (){
                  initCodeState();
                },
              )
            ],
          ),
        ),
      ),
    );
  }
}
3
likes
30
pub points
0%
popularity

Publisher

unverified uploader

A qrcode scanner flutter plugin project. Support iOS, Android.

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on flutter_plugin_qr_scanner