This repository has been archived by the owner on Jun 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.dart
95 lines (85 loc) · 2.32 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_datawedge/flutter_datawedge.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _scannerStatus = "Scanner status";
String _lastCode = '';
bool _isEnabled = true;
@override
void initState() {
super.initState();
initScanner();
}
void initScanner() {
FlutterDataWedge.initScanner(
profileName: 'FlutterDataWedge',
onScan: (result){
setState(() {
_lastCode = result.data;
});
},
onStatusUpdate: (result){
ScannerStatusType status = result.status;
setState(() {
_scannerStatus = status.toString().split('.')[1];
});
}
);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
appBarTheme: AppBarTheme(
brightness: Brightness.dark,
),
primarySwatch: Colors.blue,
accentColor: Colors.pinkAccent
),
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: const Text('Flutter DataWedge'),
),
body: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Column(
children: [
Text('Last code:'),
Text(_lastCode, style: Theme.of(context).textTheme.headline5),
],
),
SizedBox(height: 10.0),
Column(
children: [
Text('Status:'),
Text(_scannerStatus, style: Theme.of(context).textTheme.headline6),
],
),
SizedBox(height: 10.0),
ElevatedButton(
child: Text(_isEnabled ? 'Desactivate' : 'Activate'),
onPressed: () {
FlutterDataWedge.enableScanner(!_isEnabled);
setState(() {
_isEnabled = !_isEnabled;
});
},
)
],
),
),
),
);
}
}