Julian Steenbakker

imp: update example app

@@ -92,9 +92,10 @@ class _AnalyzeViewState extends State<AnalyzeView> @@ -92,9 +92,10 @@ class _AnalyzeViewState extends State<AnalyzeView>
92 icon: ValueListenableBuilder( 92 icon: ValueListenableBuilder(
93 valueListenable: controller.cameraFacingState, 93 valueListenable: controller.cameraFacingState,
94 builder: (context, state, child) { 94 builder: (context, state, child) {
95 - if (state == CameraFacing.front) { 95 + switch (state as CameraFacing) {
  96 + case CameraFacing.front:
96 return const Icon(Icons.camera_front); 97 return const Icon(Icons.camera_front);
97 - } else { 98 + case CameraFacing.back:
98 return const Icon(Icons.camera_rear); 99 return const Icon(Icons.camera_rear);
99 } 100 }
100 }, 101 },
1 -import 'dart:ui';  
2 -  
3 -import 'package:flutter/material.dart';  
4 -import 'package:mobile_scanner/mobile_scanner.dart';  
5 -  
6 -void main() {  
7 - runApp(const AnalyzeView());  
8 -}  
9 -  
10 -class AnalyzeView extends StatefulWidget {  
11 - const AnalyzeView({Key? key}) : super(key: key);  
12 -  
13 - @override  
14 - _AnalyzeViewState createState() => _AnalyzeViewState();  
15 -}  
16 -  
17 -class _AnalyzeViewState extends State<AnalyzeView>  
18 - with SingleTickerProviderStateMixin {  
19 - List<Offset> points = [];  
20 -  
21 - // CameraController cameraController = CameraController(context, width: 320, height: 150);  
22 -  
23 - String? barcode;  
24 -  
25 - @override  
26 - Widget build(BuildContext context) {  
27 - return MaterialApp(  
28 - home: Scaffold(  
29 - body: Builder(builder: (context) {  
30 - return Stack(  
31 - children: [  
32 - MobileScanner(  
33 - // fitScreen: false,  
34 - // controller: cameraController,  
35 - onDetect: (barcode, args) {  
36 - if (this.barcode != barcode.rawValue) {  
37 - this.barcode = barcode.rawValue;  
38 - if (barcode.corners != null) {  
39 - ScaffoldMessenger.of(context).showSnackBar(SnackBar(  
40 - content: Text(barcode.rawValue),  
41 - duration: const Duration(milliseconds: 200),  
42 - animation: null,  
43 - ));  
44 - setState(() {  
45 - final List<Offset> points = [];  
46 - // double factorWidth = args.size.width / 520;  
47 - // double factorHeight = wanted / args.size.height;  
48 - final size = MediaQuery.of(context).devicePixelRatio;  
49 - debugPrint('Size: ${barcode.corners}');  
50 - for (var point in barcode.corners!) {  
51 - final adjustedWith = point.dx;  
52 - final adjustedHeight = point.dy;  
53 - points.add(  
54 - Offset(adjustedWith / size, adjustedHeight / size));  
55 - // points.add(Offset((point.dx ) / size,  
56 - // (point.dy) / size));  
57 - // final differenceWidth = (args.wantedSize!.width - args.size.width) / 2;  
58 - // final differenceHeight = (args.wantedSize!.height - args.size.height) / 2;  
59 - // points.add(Offset((point.dx + differenceWidth) / size,  
60 - // (point.dy + differenceHeight) / size));  
61 - }  
62 - this.points = points;  
63 - });  
64 - }  
65 - }  
66 - // Default 640 x480  
67 - }),  
68 - CustomPaint(  
69 - painter: OpenPainter(points),  
70 - ),  
71 - // Container(  
72 - // alignment: Alignment.bottomCenter,  
73 - // margin: EdgeInsets.only(bottom: 80.0),  
74 - // child: IconButton(  
75 - // icon: ValueListenableBuilder(  
76 - // valueListenable: cameraController.torchState,  
77 - // builder: (context, state, child) {  
78 - // final color =  
79 - // state == TorchState.off ? Colors.grey : Colors.white;  
80 - // return Icon(Icons.bolt, color: color);  
81 - // },  
82 - // ),  
83 - // iconSize: 32.0,  
84 - // onPressed: () => cameraController.torch(),  
85 - // ),  
86 - // ),  
87 - ],  
88 - );  
89 - }),  
90 - ),  
91 - );  
92 - }  
93 -  
94 - @override  
95 - void dispose() {  
96 - // cameraController.dispose();  
97 - super.dispose();  
98 - }  
99 -  
100 - void display(Barcode barcode) {  
101 - Navigator.of(context).popAndPushNamed('display', arguments: barcode);  
102 - }  
103 -}  
104 -  
105 -class OpenPainter extends CustomPainter {  
106 - final List<Offset> points;  
107 -  
108 - OpenPainter(this.points);  
109 - @override  
110 - void paint(Canvas canvas, Size size) {  
111 - var paint1 = Paint()  
112 - ..color = const Color(0xff63aa65)  
113 - ..strokeWidth = 10;  
114 - //draw points on canvas  
115 - canvas.drawPoints(PointMode.points, points, paint1);  
116 - }  
117 -  
118 - @override  
119 - bool shouldRepaint(CustomPainter oldDelegate) => true;  
120 -}  
121 -  
122 -class OpacityCurve extends Curve {  
123 - @override  
124 - double transform(double t) {  
125 - if (t < 0.1) {  
126 - return t * 10;  
127 - } else if (t <= 0.9) {  
128 - return 1.0;  
129 - } else {  
130 - return (1.0 - t) * 10;  
131 - }  
132 - }  
133 -} 1 +//TODO: Create example with scanner overlay
134 2
  3 +// import 'dart:ui';
  4 +//
135 // import 'package:flutter/material.dart'; 5 // import 'package:flutter/material.dart';
136 -// import 'package:flutter/rendering.dart';  
137 // import 'package:mobile_scanner/mobile_scanner.dart'; 6 // import 'package:mobile_scanner/mobile_scanner.dart';
138 // 7 //
139 // void main() { 8 // void main() {
140 -// debugPaintSizeEnabled = false;  
141 -// runApp(HomePage()); 9 +// runApp(const AnalyzeView());
142 // } 10 // }
143 // 11 //
144 -// class HomePage extends StatefulWidget { 12 +// class AnalyzeView extends StatefulWidget {
  13 +// const AnalyzeView({Key? key}) : super(key: key);
  14 +//
145 // @override 15 // @override
146 -// HomeState createState() => HomeState(); 16 +// _AnalyzeViewState createState() => _AnalyzeViewState();
147 // } 17 // }
148 // 18 //
149 -// class HomeState extends State<HomePage> { 19 +// class _AnalyzeViewState extends State<AnalyzeView>
  20 +// with SingleTickerProviderStateMixin {
  21 +// List<Offset> points = [];
  22 +//
  23 +// // CameraController cameraController = CameraController(context, width: 320, height: 150);
  24 +//
  25 +// String? barcode;
  26 +//
150 // @override 27 // @override
151 // Widget build(BuildContext context) { 28 // Widget build(BuildContext context) {
152 -// return MaterialApp(home: MyApp()); 29 +// return MaterialApp(
  30 +// home: Scaffold(
  31 +// body: Builder(builder: (context) {
  32 +// return Stack(
  33 +// children: [
  34 +// MobileScanner(
  35 +// // fitScreen: false,
  36 +// // controller: cameraController,
  37 +// onDetect: (barcode, args) {
  38 +// if (this.barcode != barcode.rawValue) {
  39 +// this.barcode = barcode.rawValue;
  40 +// if (barcode.corners != null) {
  41 +// ScaffoldMessenger.of(context).showSnackBar(SnackBar(
  42 +// content: Text(barcode.rawValue),
  43 +// duration: const Duration(milliseconds: 200),
  44 +// animation: null,
  45 +// ));
  46 +// setState(() {
  47 +// final List<Offset> points = [];
  48 +// // double factorWidth = args.size.width / 520;
  49 +// // double factorHeight = wanted / args.size.height;
  50 +// final size = MediaQuery.of(context).devicePixelRatio;
  51 +// debugPrint('Size: ${barcode.corners}');
  52 +// for (var point in barcode.corners!) {
  53 +// final adjustedWith = point.dx;
  54 +// final adjustedHeight = point.dy;
  55 +// points.add(
  56 +// Offset(adjustedWith / size, adjustedHeight / size));
  57 +// // points.add(Offset((point.dx ) / size,
  58 +// // (point.dy) / size));
  59 +// // final differenceWidth = (args.wantedSize!.width - args.size.width) / 2;
  60 +// // final differenceHeight = (args.wantedSize!.height - args.size.height) / 2;
  61 +// // points.add(Offset((point.dx + differenceWidth) / size,
  62 +// // (point.dy + differenceHeight) / size));
  63 +// }
  64 +// this.points = points;
  65 +// });
153 // } 66 // }
154 // } 67 // }
  68 +// // Default 640 x480
  69 +// }),
  70 +// CustomPaint(
  71 +// painter: OpenPainter(points),
  72 +// ),
  73 +// // Container(
  74 +// // alignment: Alignment.bottomCenter,
  75 +// // margin: EdgeInsets.only(bottom: 80.0),
  76 +// // child: IconButton(
  77 +// // icon: ValueListenableBuilder(
  78 +// // valueListenable: cameraController.torchState,
  79 +// // builder: (context, state, child) {
  80 +// // final color =
  81 +// // state == TorchState.off ? Colors.grey : Colors.white;
  82 +// // return Icon(Icons.bolt, color: color);
  83 +// // },
  84 +// // ),
  85 +// // iconSize: 32.0,
  86 +// // onPressed: () => cameraController.torch(),
  87 +// // ),
  88 +// // ),
  89 +// ],
  90 +// );
  91 +// }),
  92 +// ),
  93 +// );
  94 +// }
155 // 95 //
156 -// class MyApp extends StatefulWidget {  
157 // @override 96 // @override
158 -// _MyAppState createState() => _MyAppState(); 97 +// void dispose() {
  98 +// // cameraController.dispose();
  99 +// super.dispose();
159 // } 100 // }
160 // 101 //
161 -// class _MyAppState extends State<MyApp> {  
162 -// String? qr;  
163 -// bool camState = false; 102 +// void display(Barcode barcode) {
  103 +// Navigator.of(context).popAndPushNamed('display', arguments: barcode);
  104 +// }
  105 +// }
164 // 106 //
  107 +// class OpenPainter extends CustomPainter {
  108 +// final List<Offset> points;
  109 +//
  110 +// OpenPainter(this.points);
165 // @override 111 // @override
166 -// initState() {  
167 -// super.initState(); 112 +// void paint(Canvas canvas, Size size) {
  113 +// var paint1 = Paint()
  114 +// ..color = const Color(0xff63aa65)
  115 +// ..strokeWidth = 10;
  116 +// //draw points on canvas
  117 +// canvas.drawPoints(PointMode.points, points, paint1);
168 // } 118 // }
169 // 119 //
170 // @override 120 // @override
171 -// Widget build(BuildContext context) {  
172 -// return Scaffold(  
173 -// appBar: AppBar(  
174 -// title: Text('Plugin example app'),  
175 -// ),  
176 -// body: Center(  
177 -// child: Column(  
178 -// crossAxisAlignment: CrossAxisAlignment.center,  
179 -// mainAxisAlignment: MainAxisAlignment.center,  
180 -// children: <Widget>[  
181 -// Expanded(  
182 -// child: camState  
183 -// ? Center(  
184 -// child: SizedBox(  
185 -// width: 300.0,  
186 -// height: 600.0,  
187 -// child: MobileScanner(  
188 -// onError: (context, error) => Text(  
189 -// error.toString(),  
190 -// style: TextStyle(color: Colors.red),  
191 -// ),  
192 -// qrCodeCallback: (code) {  
193 -// setState(() {  
194 -// qr = code;  
195 -// });  
196 -// },  
197 -// child: Container(  
198 -// decoration: BoxDecoration(  
199 -// color: Colors.transparent,  
200 -// border: Border.all(  
201 -// color: Colors.orange,  
202 -// width: 10.0,  
203 -// style: BorderStyle.solid),  
204 -// ),  
205 -// ),  
206 -// ),  
207 -// ),  
208 -// )  
209 -// : Center(child: Text("Camera inactive"))),  
210 -// Text("QRCODE: $qr"),  
211 -// ],  
212 -// ),  
213 -// ),  
214 -// floatingActionButton: FloatingActionButton(  
215 -// child: Text(  
216 -// "press me",  
217 -// textAlign: TextAlign.center,  
218 -// ),  
219 -// onPressed: () {  
220 -// setState(() {  
221 -// camState = !camState;  
222 -// });  
223 -// }),  
224 -// ); 121 +// bool shouldRepaint(CustomPainter oldDelegate) => true;
  122 +// }
  123 +//
  124 +// class OpacityCurve extends Curve {
  125 +// @override
  126 +// double transform(double t) {
  127 +// if (t < 0.1) {
  128 +// return t * 10;
  129 +// } else if (t <= 0.9) {
  130 +// return 1.0;
  131 +// } else {
  132 +// return (1.0 - t) * 10;
  133 +// }
225 // } 134 // }
226 // } 135 // }
  136 +//
  137 +// // import 'package:flutter/material.dart';
  138 +// // import 'package:flutter/rendering.dart';
  139 +// // import 'package:mobile_scanner/mobile_scanner.dart';
  140 +// //
  141 +// // void main() {
  142 +// // debugPaintSizeEnabled = false;
  143 +// // runApp(HomePage());
  144 +// // }
  145 +// //
  146 +// // class HomePage extends StatefulWidget {
  147 +// // @override
  148 +// // HomeState createState() => HomeState();
  149 +// // }
  150 +// //
  151 +// // class HomeState extends State<HomePage> {
  152 +// // @override
  153 +// // Widget build(BuildContext context) {
  154 +// // return MaterialApp(home: MyApp());
  155 +// // }
  156 +// // }
  157 +// //
  158 +// // class MyApp extends StatefulWidget {
  159 +// // @override
  160 +// // _MyAppState createState() => _MyAppState();
  161 +// // }
  162 +// //
  163 +// // class _MyAppState extends State<MyApp> {
  164 +// // String? qr;
  165 +// // bool camState = false;
  166 +// //
  167 +// // @override
  168 +// // initState() {
  169 +// // super.initState();
  170 +// // }
  171 +// //
  172 +// // @override
  173 +// // Widget build(BuildContext context) {
  174 +// // return Scaffold(
  175 +// // appBar: AppBar(
  176 +// // title: Text('Plugin example app'),
  177 +// // ),
  178 +// // body: Center(
  179 +// // child: Column(
  180 +// // crossAxisAlignment: CrossAxisAlignment.center,
  181 +// // mainAxisAlignment: MainAxisAlignment.center,
  182 +// // children: <Widget>[
  183 +// // Expanded(
  184 +// // child: camState
  185 +// // ? Center(
  186 +// // child: SizedBox(
  187 +// // width: 300.0,
  188 +// // height: 600.0,
  189 +// // child: MobileScanner(
  190 +// // onError: (context, error) => Text(
  191 +// // error.toString(),
  192 +// // style: TextStyle(color: Colors.red),
  193 +// // ),
  194 +// // qrCodeCallback: (code) {
  195 +// // setState(() {
  196 +// // qr = code;
  197 +// // });
  198 +// // },
  199 +// // child: Container(
  200 +// // decoration: BoxDecoration(
  201 +// // color: Colors.transparent,
  202 +// // border: Border.all(
  203 +// // color: Colors.orange,
  204 +// // width: 10.0,
  205 +// // style: BorderStyle.solid),
  206 +// // ),
  207 +// // ),
  208 +// // ),
  209 +// // ),
  210 +// // )
  211 +// // : Center(child: Text("Camera inactive"))),
  212 +// // Text("QRCODE: $qr"),
  213 +// // ],
  214 +// // ),
  215 +// // ),
  216 +// // floatingActionButton: FloatingActionButton(
  217 +// // child: Text(
  218 +// // "press me",
  219 +// // textAlign: TextAlign.center,
  220 +// // ),
  221 +// // onPressed: () {
  222 +// // setState(() {
  223 +// // camState = !camState;
  224 +// // });
  225 +// // }),
  226 +// // );
  227 +// // }
  228 +// // }