@@ -36,7 +36,7 @@ class HomePage extends StatefulWidget {
36
36
}
37
37
38
38
class _HomePageState extends State <HomePage > {
39
- final _scaffoldKey = new GlobalKey <ScaffoldState >();
39
+ final _scaffoldKey = new GlobalKey <ScaffoldMessengerState >();
40
40
final _formKey = GlobalKey <FormState >();
41
41
final _verticalSizeBox = const SizedBox (height: 20.0 );
42
42
final _horizontalSizeBox = const SizedBox (width: 10.0 );
@@ -46,12 +46,12 @@ class _HomePageState extends State<HomePage> {
46
46
color: Colors .red,
47
47
);
48
48
int _radioValue = 0 ;
49
- CheckoutMethod _method;
49
+ CheckoutMethod _method = CheckoutMethod .selectable ;
50
50
bool _inProgress = false ;
51
- String _cardNumber;
52
- String _cvv;
53
- int _expiryMonth = 0 ;
54
- int _expiryYear = 0 ;
51
+ String ? _cardNumber;
52
+ String ? _cvv;
53
+ int ? _expiryMonth;
54
+ int ? _expiryYear;
55
55
56
56
@override
57
57
void initState () {
@@ -79,22 +79,20 @@ class _HomePageState extends State<HomePage> {
79
79
child: const Text ('Initalize transaction from:' ),
80
80
),
81
81
new Expanded (
82
- child: new Column (
83
- mainAxisSize: MainAxisSize .min,
84
- children: < Widget > [
85
- new RadioListTile <int >(
86
- value: 0 ,
87
- groupValue: _radioValue,
88
- onChanged: _handleRadioValueChanged,
89
- title: const Text ('Local' ),
90
- ),
91
- new RadioListTile <int >(
92
- value: 1 ,
93
- groupValue: _radioValue,
94
- onChanged: _handleRadioValueChanged,
95
- title: const Text ('Server' ),
96
- ),
97
- ]),
82
+ child: new Column (mainAxisSize: MainAxisSize .min, children: < Widget > [
83
+ new RadioListTile <int >(
84
+ value: 0 ,
85
+ groupValue: _radioValue,
86
+ onChanged: _handleRadioValueChanged,
87
+ title: const Text ('Local' ),
88
+ ),
89
+ new RadioListTile <int >(
90
+ value: 1 ,
91
+ groupValue: _radioValue,
92
+ onChanged: _handleRadioValueChanged,
93
+ title: const Text ('Server' ),
94
+ ),
95
+ ]),
98
96
)
99
97
],
100
98
),
@@ -105,7 +103,7 @@ class _HomePageState extends State<HomePage> {
105
103
border: const UnderlineInputBorder (),
106
104
labelText: 'Card number' ,
107
105
),
108
- onSaved: (String value) => _cardNumber = value,
106
+ onSaved: (String ? value) => _cardNumber = value,
109
107
),
110
108
_verticalSizeBox,
111
109
new Row (
@@ -118,7 +116,7 @@ class _HomePageState extends State<HomePage> {
118
116
border: const UnderlineInputBorder (),
119
117
labelText: 'CVV' ,
120
118
),
121
- onSaved: (String value) => _cvv = value,
119
+ onSaved: (String ? value) => _cvv = value,
122
120
),
123
121
),
124
122
_horizontalSizeBox,
@@ -128,8 +126,7 @@ class _HomePageState extends State<HomePage> {
128
126
border: const UnderlineInputBorder (),
129
127
labelText: 'Expiry Month' ,
130
128
),
131
- onSaved: (String value) =>
132
- _expiryMonth = int .tryParse (value),
129
+ onSaved: (String ? value) => _expiryMonth = int .tryParse (value ?? "" ),
133
130
),
134
131
),
135
132
_horizontalSizeBox,
@@ -139,8 +136,7 @@ class _HomePageState extends State<HomePage> {
139
136
border: const UnderlineInputBorder (),
140
137
labelText: 'Expiry Year' ,
141
138
),
142
- onSaved: (String value) =>
143
- _expiryYear = int .tryParse (value),
139
+ onSaved: (String ? value) => _expiryYear = int .tryParse (value ?? "" ),
144
140
),
145
141
)
146
142
],
@@ -170,16 +166,14 @@ class _HomePageState extends State<HomePage> {
170
166
: new Column (
171
167
mainAxisSize: MainAxisSize .min,
172
168
children: < Widget > [
173
- _getPlatformButton (
174
- 'Charge Card' , () => _startAfreshCharge ()),
169
+ _getPlatformButton ('Charge Card' , () => _startAfreshCharge ()),
175
170
_verticalSizeBox,
176
171
_border,
177
172
new SizedBox (
178
173
height: 40.0 ,
179
174
),
180
175
new Row (
181
- mainAxisAlignment:
182
- MainAxisAlignment .spaceBetween,
176
+ mainAxisAlignment: MainAxisAlignment .spaceBetween,
183
177
crossAxisAlignment: CrossAxisAlignment .center,
184
178
children: < Widget > [
185
179
new Flexible (
@@ -191,21 +185,17 @@ class _HomePageState extends State<HomePage> {
191
185
isDense: true ,
192
186
hintText: 'Checkout method' ,
193
187
),
194
- isEmpty: _method == null ,
195
- child: new DropdownButton <
196
- CheckoutMethod >(
188
+ child: new DropdownButton <CheckoutMethod >(
197
189
value: _method,
198
190
isDense: true ,
199
- onChanged: (CheckoutMethod value) {
200
- setState (( ) {
201
- _method = value;
202
- });
191
+ onChanged: (CheckoutMethod ? value) {
192
+ if (value != null ) {
193
+ setState (() => _method = value) ;
194
+ }
203
195
},
204
196
items: banks.map ((String value) {
205
- return new DropdownMenuItem <
206
- CheckoutMethod >(
207
- value:
208
- _parseStringToMethod (value),
197
+ return new DropdownMenuItem <CheckoutMethod >(
198
+ value: _parseStringToMethod (value),
209
199
child: new Text (value),
210
200
);
211
201
}).toList (),
@@ -239,21 +229,17 @@ class _HomePageState extends State<HomePage> {
239
229
);
240
230
}
241
231
242
- void _handleRadioValueChanged (int value) =>
243
- setState (() => _radioValue = value);
232
+ void _handleRadioValueChanged (int ? value) {
233
+ if (value != null ) setState (() => _radioValue = value);
234
+ }
244
235
245
236
_handleCheckout (BuildContext context) async {
246
- if (_method == null ) {
247
- _showMessage ('Select checkout method first' );
248
- return ;
249
- }
250
-
251
237
if (_method != CheckoutMethod .card && _isLocal) {
252
238
_showMessage ('Select server initialization method at the top' );
253
239
return ;
254
240
}
255
241
setState (() => _inProgress = true );
256
- _formKey.currentState.save ();
242
+ _formKey.currentState? .save ();
257
243
Charge charge = Charge ()
258
244
..amount = 10000 // In base currency
259
245
..email = 'customer@email.com'
@@ -285,7 +271,7 @@ class _HomePageState extends State<HomePage> {
285
271
}
286
272
287
273
_startAfreshCharge () async {
288
- _formKey.currentState.save ();
274
+ _formKey.currentState? .save ();
289
275
290
276
Charge charge = Charge ();
291
277
charge.card = _getCardFromUI ();
@@ -388,11 +374,8 @@ class _HomePageState extends State<HomePage> {
388
374
),
389
375
);
390
376
} else {
391
- widget = new RaisedButton (
377
+ widget = new ElevatedButton (
392
378
onPressed: function,
393
- color: Colors .blueAccent,
394
- textColor: Colors .white,
395
- padding: const EdgeInsets .symmetric (vertical: 13.0 , horizontal: 10.0 ),
396
379
child: new Text (
397
380
string.toUpperCase (),
398
381
style: const TextStyle (fontSize: 17.0 ),
@@ -402,12 +385,12 @@ class _HomePageState extends State<HomePage> {
402
385
return widget;
403
386
}
404
387
405
- Future <String > _fetchAccessCodeFrmServer (String reference) async {
388
+ Future <String ? > _fetchAccessCodeFrmServer (String reference) async {
406
389
String url = '$backendUrl /new-access-code' ;
407
- String accessCode;
390
+ String ? accessCode;
408
391
try {
409
392
print ("Access code url = $url " );
410
- http.Response response = await http.get (url);
393
+ http.Response response = await http.get (Uri . parse ( url) );
411
394
accessCode = response.body;
412
395
print ('Response for access code = $accessCode ' );
413
396
} catch (e) {
@@ -421,11 +404,11 @@ class _HomePageState extends State<HomePage> {
421
404
return accessCode;
422
405
}
423
406
424
- void _verifyOnServer (String reference) async {
407
+ void _verifyOnServer (String ? reference) async {
425
408
_updateStatus (reference, 'Verifying...' );
426
409
String url = '$backendUrl /verify/$reference ' ;
427
410
try {
428
- http.Response response = await http.get (url);
411
+ http.Response response = await http.get (Uri . parse ( url) );
429
412
var body = response.body;
430
413
_updateStatus (reference, body);
431
414
} catch (e) {
@@ -437,19 +420,16 @@ class _HomePageState extends State<HomePage> {
437
420
setState (() => _inProgress = false );
438
421
}
439
422
440
- _updateStatus (String reference, String message) {
441
- _showMessage ('Reference: $reference \n\ Response: $message ' ,
442
- const Duration (seconds: 7 ));
423
+ _updateStatus (String ? reference, String message) {
424
+ _showMessage ('Reference: $reference \n\ Response: $message ' , const Duration (seconds: 7 ));
443
425
}
444
426
445
- _showMessage (String message,
446
- [Duration duration = const Duration (seconds: 4 )]) {
447
- _scaffoldKey.currentState.showSnackBar (new SnackBar (
427
+ _showMessage (String message, [Duration duration = const Duration (seconds: 4 )]) {
428
+ _scaffoldKey.currentState? .showSnackBar (new SnackBar (
448
429
content: new Text (message),
449
430
duration: duration,
450
431
action: new SnackBarAction (
451
- label: 'CLOSE' ,
452
- onPressed: () => _scaffoldKey.currentState.removeCurrentSnackBar ()),
432
+ label: 'CLOSE' , onPressed: () => _scaffoldKey.currentState? .removeCurrentSnackBar ()),
453
433
));
454
434
}
455
435
0 commit comments