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

outdated

A new Flutter plugin.

example/lib/main.dart

import 'dart:developer';
import 'dart:io';

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

import 'package:flutter/services.dart';
import 'package:image_picker/image_picker.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> {

  String scantest = "";

  @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 RaisedButton(
                        child: Text("扫码二维码(单次)${scantest}"),
                        onPressed: (){
                          ScannerView.getScanResult(ctx, callback: (scanResult) async {
                            //do something
                            scantest = scanResult;
                            setState(() {

                            });
                          });
                        });
                  },),

                  Builder(builder: (BuildContext ctx) {
                    return RaisedButton(
                        child: Text("扫码二维码(连续)"),
                        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

A new Flutter plugin.

Homepage

License

unknown (LICENSE)

Dependencies

flutter, fluttertoast, image_picker

More

Packages that depend on scanner_view