-
Notifications
You must be signed in to change notification settings - Fork 31
/
main.dart
176 lines (164 loc) · 5.19 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import 'package:flutter/material.dart';
import 'package:jumio_mobile_sdk_flutter/jumio_mobile_sdk_flutter.dart';
import 'package:jumiomobilesdk_example/credentials.dart';
void main() {
runApp(DemoApp());
}
class DemoApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: HomePage(
title: "Mobile SDK Demo App",
));
}
}
class HomePage extends StatefulWidget {
final String? title;
HomePage({Key? key, this.title}) : super(key: key);
@override
State<StatefulWidget> createState() => _HomePageState(title);
}
class _HomePageState extends State<HomePage> {
final String? title;
final tokenInputController = TextEditingController();
bool pressedUS = false;
bool pressedEU = false;
bool pressedSGP = false;
_HomePageState(this.title);
@override
void dispose() {
tokenInputController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title!),
),
body: Center(
child: IntrinsicWidth(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Container(
width: 250.0,
child: TextFormField(
controller: tokenInputController,
decoration: InputDecoration(
border: UnderlineInputBorder(),
labelText: 'Authorization token'),
),
),
ElevatedButton(
child: Text("Start"),
onPressed: () {
_start(tokenInputController.text);
},
),
ElevatedButton(
child: Text("US"),
style: ElevatedButton.styleFrom(
backgroundColor: pressedUS ? Colors.yellow : Colors.blue, // background
foregroundColor: Colors.white, // foreground
),
onPressed: () => {
setState(() {
pressedUS = !pressedUS;
pressedEU = false;
pressedSGP = false;
}),
DATACENTER = 'US',
},
),
ElevatedButton(
child: Text("EU"),
style: ElevatedButton.styleFrom(
backgroundColor: pressedEU ? Colors.yellow : Colors.blue, // background
foregroundColor: Colors.white, // foreground
),
onPressed: () => {
setState(() {
pressedEU = !pressedEU;
pressedUS = false;
pressedSGP = false;
}),
DATACENTER = 'EU',
},
),
ElevatedButton(
child: Text("SG"),
style: ElevatedButton.styleFrom(
backgroundColor: pressedSGP ? Colors.yellow : Colors.blue, // background
foregroundColor: Colors.white, // foreground
),
onPressed: () => {
setState(() {
pressedSGP = !pressedSGP;
pressedUS = false;
pressedEU = false;
}),
DATACENTER = 'SG',
},
),
],
),
),
),
);
}
Future<void> _start(String authorizationToken) async {
await _logErrors(() async {
await Jumio.init(authorizationToken, DATACENTER);
final result = await Jumio.start(
{
// "background": "#AC3D9A",
// "primaryColor": "#FF5722",
// "loadingCircleIcon": "#F2F233",
// "loadingCirclePlain": "#57ffc7",
// "loadingCircleGradientStart": "#EC407A",
// "loadingCircleGradientEnd": "#bc2e41",
// "loadingErrorCircleGradientStart": "#AC3D9A",
// "loadingErrorCircleGradientEnd": "#C31322",
// "primaryButtonBackground": {"light": "#D900ff00", "dark": "#9Edd9E"}
}
);
await _showDialogWithMessage("Jumio has completed. Result: $result");
});
}
Future<void> _logErrors(Future<void> Function() block) async {
try {
await block();
} catch (error) {
await _showDialogWithMessage(error.toString(), "Error");
}
}
Future<void> _showDialogWithMessage(String message,
[String title = "Result"]) async {
return showDialog<void>(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return AlertDialog(
title: Text(title),
content: SingleChildScrollView(child: Text(message)),
actions: <Widget>[
TextButton(
child: Text('OK'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
}