Import 'Dartdeveloper'
Import 'Dartdeveloper'
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:qr_code_scanner/qr_code_scanner.dart';
void main() {
runApp(const MyApp());
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Flutter Demo Home Page')),
body: Center(
child: ElevatedButton(
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => const QRViewExample(),
));
},
child: const Text('qrView'),
),
),
);
}
}
@override
State<StatefulWidget> createState() => _QRViewExampleState();
}
// In order to get hot reload to work we need to pause the camera if the platform
// is android, or resume the camera if the platform is iOS.
@override
void reassemble() {
super.reassemble();
if (Platform.isAndroid) {
controller!.pauseCamera();
}
controller!.resumeCamera();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: <Widget>[
SizedBox(
height: 100,
),
Expanded(flex: 1, child: _buildQrView(context)),
Expanded(
flex: 1,
child: FittedBox(
fit: BoxFit.contain,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
if (result != null)
Column(
children: [
Icon(
Icons.qr_code_2,
size: 20,
),
SizedBox(
width: 10,
),
Text(
'Barcode Type: ${describeEnum(result!.format)} '),
Text(' Data: ${result!.code}'),
],
)
else
const Text('Scan a code'),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
margin: const EdgeInsets.all(8),
child: ElevatedButton(
onPressed: () async {
await controller?.toggleFlash();
setState(() {});
},
child: FutureBuilder(
future: controller?.getFlashStatus(),
builder: (context, snapshot) {
IconData flashIcon = Icons
.flashlight_off_outlined; // Default to flash off
icon
if (snapshot.connectionState ==
ConnectionState.done) {
// If future completed, check snapshot data
if (snapshot.hasData &&
snapshot.data != null &&
snapshot.data!) {
flashIcon = Icons
.flashlight_on_outlined; // If true, set
flash on icon
}
}
return Row(
children: [
Icon(
flashIcon,
size: 20,
),
SizedBox(
width: 10,
),
Text(
'Flash: ${snapshot.data ?? "Loading..."}',
style: TextStyle(fontSize: 12)),
],
);
},
),
),
),
Container(
margin: const EdgeInsets.all(8),
child: ElevatedButton(
onPressed: () async {
await controller?.flipCamera();
setState(() {});
},
child: FutureBuilder(
future: controller?.getCameraInfo(),
builder: (context, snapshot) {
if (snapshot.data != null) {
return Row(
children: [
Icon(
Icons.cameraswitch_outlined,
size: 20,
),
SizedBox(
width: 10,
),
// Text(
// 'Camera facing $
{describeEnum(snapshot.data!)}'),
Text('${describeEnum(snapshot.data!)}',
style: TextStyle(fontSize: 12)),
],
);
} else {
return const Text('loading');
}
},
)),
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
margin: const EdgeInsets.all(8),
child: ElevatedButton(
onPressed: () async {
await controller?.pauseCamera();
},
child: Row(
children: [
Icon(
Icons.pause,
size: 20,
),
SizedBox(
width: 10,
),
const Text('pause',
style: TextStyle(fontSize: 12)),
],
),
),
),
Container(
margin: const EdgeInsets.all(8),
child: ElevatedButton(
onPressed: () async {
await controller?.resumeCamera();
},
child: Row(
children: [
Row(
children: [
Icon(
Icons.play_arrow,
size: 20,
),
SizedBox(
width: 10,
),
const Text('resume',
style: TextStyle(fontSize: 12)),
],
),
],
),
),
)
],
),
],
),
),
)
],
),
);
}
@override
void dispose() {
controller?.dispose();
super.dispose();
}
}