scanner_view 0.0.3 scanner_view: ^0.0.3 copied to clipboard
A new Flutter plugin.
import 'dart:developer';
import 'package:flutter/material.dart';
import 'dart:async';
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 RaisedButton(
child: Text("扫码二维码(单次)"),
onPressed: (){
ScannerView.getScanResult(ctx, callback: (scanResult) async {
//do something
});
});
},),
Builder(builder: (BuildContext ctx) {
return RaisedButton(
child: Text("扫码二维码(连续)"),
onPressed: (){
ScannerView.getScanResult(ctx, isSingle: false, callback: (scanResult) async {
await Future.delayed(Duration(milliseconds: 2000));
});
});
},),
],
)
)
),
);
}
}