scanner_view 1.0.1 copy "scanner_view: ^1.0.1" to clipboard
scanner_view: ^1.0.1 copied to clipboard

outdated

Flutter plugin for QR scanner.

example/lib/main.dart

import 'dart:async';

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

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

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

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState(BuildContext context,
      {bool isSingle = true}) async {
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      ScannerView.getScanResult(context, isSingle: isSingle,
          callback: (scanResult) async {
        await Future.delayed(Duration(milliseconds: 2000));
      });
    } on PlatformException {}

    // 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;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: Text("扫码"),
          ),
          body: Center(
              child: Column(
            children: [
              Builder(
                builder: (BuildContext ctx) {
                  return TextButton(
                      child: Text("单次扫码"),
                      style: ButtonStyle(
                        backgroundColor: MaterialStateProperty.all(Colors.blueAccent),
                        foregroundColor:MaterialStateProperty.all(Colors.white),
                      ),
                      onPressed: () {
                        ScannerView.getScanResult(ctx,
                            callback: (scanResult) async {
                          print("扫描结果:$scanResult");
                        });
                      });
                },
              ),
              Builder(
                builder: (BuildContext ctx) {
                  return TextButton(
                      child: Text("连续扫码"),
                      style: ButtonStyle(
                        backgroundColor: MaterialStateProperty.all(Colors.blueAccent),
                        foregroundColor:MaterialStateProperty.all(Colors.white),
                      ),
                      onPressed: () {
                        ScannerView.getScanResult(ctx, isSingle: false,
                            callback: (scanResult) async {
                          await Future.delayed(Duration(milliseconds: 2000));
                        });
                      });
                },
              ),
            ],
          ))),
    );
  }
}
1
likes
0
pub points
41%
popularity

Publisher

unverified uploader

Flutter plugin for QR scanner.

Homepage

License

unknown (LICENSE)

Dependencies

flutter, fluttertoast, image_picker

More

Packages that depend on scanner_view