qr_mobile_vision 5.0.2 qr_mobile_vision: ^5.0.2 copied to clipboard
Plugin for reading QR codes using Firebase's Mobile Vision API.
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:qr_mobile_vision/qr_camera.dart';
void main() {
debugPaintSizeEnabled = false;
runApp(const HomePage());
}
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
HomeState createState() => HomeState();
}
class HomeState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return const MaterialApp(home: MyApp());
}
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
MyAppState createState() => MyAppState();
}
class MyAppState extends State<MyApp> {
String? qr;
bool camState = false;
bool dirState = false;
@override
initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
actions: <Widget>[
IconButton(icon: const Icon(Icons.light), onPressed: _swapBackLightState),
],
),
body: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text("Back"),
Switch(value: dirState, onChanged: (val) => setState(() => dirState = val)),
const Text("Front"),
],
),
Expanded(
child: camState
? Center(
child: SizedBox(
width: 300.0,
height: 600.0,
child: QrCamera(
onError: (context, error) => Text(
error.toString(),
style: const TextStyle(color: Colors.red),
),
cameraDirection: dirState ? CameraDirection.FRONT : CameraDirection.BACK,
qrCodeCallback: (code) {
setState(() {
qr = code;
});
},
child: Container(
decoration: BoxDecoration(
color: Colors.transparent,
border: Border.all(
color: Colors.orange,
width: 10.0,
style: BorderStyle.solid,
),
),
),
),
),
)
: const Center(child: Text("Camera inactive"))),
Text("QRCODE: $qr"),
],
),
),
floatingActionButton: FloatingActionButton(
child: const Text(
"on/off",
textAlign: TextAlign.center,
),
onPressed: () {
setState(() {
camState = !camState;
});
}),
);
}
_swapBackLightState() async {
QrCamera.toggleFlash();
}
}