-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.dart
950 lines (896 loc) · 27.5 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
import 'dart:async' show StreamSubscription;
import 'dart:io';
import 'dart:convert';
import 'package:flutter/material.dart' hide ColorScheme;
import 'package:flutter/services.dart';
import 'package:shared_preferences/shared_preferences.dart'
show SharedPreferences;
import 'package:flutter_authgear/flutter_authgear.dart';
const redirectURI = "com.authgear.exampleapp.flutter://host/path";
var wechatRedirectURI = "";
const _nativeMethodChannel = MethodChannel("example");
ColorScheme colorSchemeFromContext(BuildContext context) {
final brightness = MediaQuery.of(context).platformBrightness;
switch (brightness) {
case Brightness.light:
return ColorScheme.light;
case Brightness.dark:
return ColorScheme.dark;
}
}
void main() {
if (Platform.isIOS) {
wechatRedirectURI =
"https://authgear-demo-flutter.pandawork.com/authgear/open_wechat_app";
}
if (Platform.isAndroid) {
wechatRedirectURI =
"com.authgear.exampleapp.flutter://host/open_wechat_app";
}
// debugPaintSizeEnabled = true;
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
final ios = BiometricOptionsIOS(
localizedReason: "Use biometric to sign in",
constraint: BiometricAccessConstraintIOS.biometryCurrentSet,
policy: BiometricLAPolicy.deviceOwnerAuthenticationWithBiometrics,
);
final android = BiometricOptionsAndroid(
title: "Sign in with biometric",
subtitle: "Sign in securely with biometric",
description: "Use your enrolled biometric to sign in",
negativeButtonText: "Cancel",
constraint: [BiometricAccessConstraintAndroid.biometricStrong],
invalidatedByBiometricEnrollment: true,
);
String _showError(dynamic e) {
if (e is BiometricPrivateKeyNotFoundException) {
if (Platform.isIOS) {
return "Your Touch ID or Face ID has changed. For security reason, you have to set up biometric authentication again.";
}
if (Platform.isAndroid) {
return "Your biometric info has changed. For security reason, you have to set up biometric authentication again.";
}
}
if (e is BiometricNoEnrollmentException) {
if (Platform.isIOS) {
return "You do not have Face ID or Touch ID set up yet. Please set it up first.";
}
if (Platform.isAndroid) {
return "You have not set up biometric yet. Please set up your fingerprint or face.";
}
}
if (e is BiometricNotSupportedOrPermissionDeniedException) {
if (Platform.isIOS) {
return "If the developer should performed checking, then it is likely that you have denied the permission of Face ID. Please enable it in Settings";
}
if (Platform.isAndroid) {
return "Your device does not support biometric. The developer should have checked this and not letting you to see feature that requires biometric";
}
}
if (e is BiometricNoPasscodeException) {
if (Platform.isIOS) {
return "You device does not have passcode set up. Please set up a passcode.";
}
if (Platform.isAndroid) {
return "You device does not have credential set up. Please set up either a PIN, a pattern or a password.";
}
}
if (e is BiometricLockoutException) {
return "The biometric is locked out due to too many failed attempts. The developer should handle this error by using normal authentication as a fallback. So normally you should not see this error";
}
return "$e";
}
class TextFieldWithLabel extends StatelessWidget {
final String label;
final String hintText;
final TextEditingController controller;
const TextFieldWithLabel({
Key? key,
required this.label,
required this.hintText,
required this.controller,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Column(
children: [
Align(
alignment: Alignment.centerLeft,
child: Text(label),
),
TextField(
controller: controller,
decoration: InputDecoration(
hintText: hintText,
),
),
],
);
}
}
class SwitchWithLabel extends StatelessWidget {
final String label;
final bool value;
final ValueChanged<bool> onChanged;
const SwitchWithLabel({
Key? key,
required this.label,
required this.value,
required this.onChanged,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
child: Text(label),
),
Switch(
value: value,
onChanged: onChanged,
),
],
);
}
}
class RadioOption<T> {
final String label;
final T? value;
RadioOption({required this.label, required this.value});
}
class RadioGroup<T> extends StatelessWidget {
final String title;
final T? groupValue;
final List<RadioOption<T>> options;
final ValueChanged<T?> onChanged;
const RadioGroup({
Key? key,
required this.title,
required this.groupValue,
required this.options,
required this.onChanged,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Column(
children: [
SizedBox(
width: double.infinity,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 0),
child: Text(title),
),
),
for (var option in options)
RadioListTile<T?>(
value: option.value,
groupValue: groupValue,
onChanged: onChanged,
title: Text(option.label),
),
],
);
}
}
class SessionStateButton extends StatelessWidget {
final SessionState sessionState;
final SessionState targetState;
final void Function()? onPressed;
final String label;
const SessionStateButton({
Key? key,
required this.sessionState,
required this.targetState,
required this.onPressed,
required this.label,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return TextButton(
onPressed: sessionState == targetState ? onPressed : null,
child: Text(label),
);
}
}
class _MyAppState extends State<MyApp> {
Authgear _authgear = Authgear(endpoint: "", clientID: "");
late SharedPreferences _sharedPreferences;
final TextEditingController _endpointController = TextEditingController();
final TextEditingController _clientIDController = TextEditingController();
final TextEditingController _authenticationFlowGroupController =
TextEditingController();
StreamSubscription<SessionStateChangeEvent>? _sub;
bool _loading = false;
bool _useTransientTokenStorage = false;
bool _isSsoEnabled = false;
bool _useWebKitWebView = false;
bool _isBiometricEnabled = false;
bool get _unconfigured {
return _authgear.endpoint != _endpointController.text ||
_authgear.clientID != _clientIDController.text;
}
UserInfo? _userInfo;
bool get _isAnonymous {
final userInfo = _userInfo;
if (userInfo == null) {
return false;
}
return userInfo.isAnonymous;
}
AuthenticationPage? _page;
ColorScheme? _colorScheme;
ColorScheme? _getColorScheme(BuildContext context) {
if (_colorScheme != null) {
return _colorScheme;
}
return colorSchemeFromContext(context);
}
@override
void initState() {
super.initState();
_endpointController.addListener(() {
setState(() {});
});
_clientIDController.addListener(() {
setState(() {});
});
void init() async {
_sharedPreferences = await SharedPreferences.getInstance();
final endpoint = _sharedPreferences.getString("authgear.endpoint");
final clientID = _sharedPreferences.getString("authgear.clientID");
if (endpoint != null && clientID != null) {
_endpointController.text = endpoint;
_clientIDController.text = clientID;
}
}
init();
}
@override
void dispose() {
_sub?.cancel();
_endpointController.dispose();
_clientIDController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Builder(
builder: (BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: ListView(
children: [
Container(
padding:
const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
child: TextFieldWithLabel(
label: "Client ID",
hintText: "Enter client ID",
controller: _clientIDController,
),
),
Container(
padding:
const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
child: TextFieldWithLabel(
label: "Endpoint",
hintText: "Enter Authegar endpoint",
controller: _endpointController,
),
),
Container(
padding:
const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
child: TextFieldWithLabel(
label: "Authentication Flow Group",
hintText: "Enter flow group",
controller: _authenticationFlowGroupController,
),
),
RadioGroup<AuthenticationPage>(
title: "Intial Page",
groupValue: _page,
options: [
RadioOption(
label: "Unset",
value: null,
),
RadioOption(
label: "login",
value: AuthenticationPage.login,
),
RadioOption(
label: "signup",
value: AuthenticationPage.signup,
),
],
onChanged: (newPage) {
setState(() {
_page = newPage;
});
},
),
RadioGroup<ColorScheme>(
title: "Color Scheme",
groupValue: _colorScheme,
options: [
RadioOption(
label: "Use System",
value: null,
),
RadioOption(
label: ColorScheme.light.name,
value: ColorScheme.light,
),
RadioOption(
label: ColorScheme.dark.name,
value: ColorScheme.dark,
),
],
onChanged: (newColorScheme) {
setState(() {
_colorScheme = newColorScheme;
});
},
),
Container(
padding:
const EdgeInsets.symmetric(vertical: 0, horizontal: 16),
child: SwitchWithLabel(
label: "Use TransientTokenStorage",
value: _useTransientTokenStorage,
onChanged: (newValue) {
setState(() {
_useTransientTokenStorage = newValue;
});
},
),
),
Container(
padding:
const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
child: SwitchWithLabel(
label: "Is SSO Enabled",
value: _isSsoEnabled,
onChanged: (newValue) {
setState(() {
_isSsoEnabled = newValue;
});
},
)),
Container(
padding:
const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
child: SwitchWithLabel(
label: "Use WebKit WebView",
value: _useWebKitWebView,
onChanged: (newValue) {
setState(() {
_useWebKitWebView = newValue;
});
},
)),
Container(
padding:
const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
child: Text(
"SessionState: ${_authgear.sessionState.toString()}"),
),
TextButton(
onPressed: () {
_onPressConfigure();
},
child: const Text("Configure"),
),
SessionStateButton(
sessionState: _authgear.sessionState,
targetState: SessionState.noSession,
label: "Authenticate",
onPressed: _unconfigured || _loading
? null
: () {
_onPressAuthenticate(context);
},
),
SessionStateButton(
sessionState: _authgear.sessionState,
targetState: SessionState.noSession,
label: "Authenticate Anonymously",
onPressed: _unconfigured || _loading
? null
: () {
_onPressAuthenticateAnonymously(context);
},
),
SessionStateButton(
sessionState: _authgear.sessionState,
targetState: SessionState.authenticated,
label: "Promote Anonymous User",
onPressed: _unconfigured || _loading || !_isAnonymous
? null
: () {
_onPressPromoteAnonymousUser(context);
},
),
SessionStateButton(
sessionState: _authgear.sessionState,
targetState: SessionState.noSession,
label: "Authenticate Biometric",
onPressed: _unconfigured || _loading || !_isBiometricEnabled
? null
: () {
_onPressAuthenticateBiometric(context);
},
),
SessionStateButton(
sessionState: _authgear.sessionState,
targetState: SessionState.authenticated,
label: "Reauthenticate (web-only)",
onPressed: _unconfigured || _loading
? null
: () {
_onPressReauthenticateWeb(context);
},
),
SessionStateButton(
sessionState: _authgear.sessionState,
targetState: SessionState.authenticated,
label: "Reauthenticate (biometric or web)",
onPressed: _unconfigured || _loading
? null
: () {
_onPressReauthenticate(context);
},
),
SessionStateButton(
sessionState: _authgear.sessionState,
targetState: SessionState.authenticated,
label: "Enable Biometric",
onPressed: _unconfigured ||
_loading ||
_isBiometricEnabled ||
_isAnonymous
? null
: () {
_onPressEnableBiometric(context);
},
),
SessionStateButton(
sessionState: _authgear.sessionState,
targetState: SessionState.authenticated,
label: "Disable Biometric",
onPressed: _unconfigured || _loading || !_isBiometricEnabled
? null
: () {
_onPressDisableBiometric(context);
},
),
SessionStateButton(
sessionState: _authgear.sessionState,
targetState: SessionState.authenticated,
label: "Get UserInfo",
onPressed: _unconfigured || _loading
? null
: () {
_onPressGetUserInfo(context);
},
),
SessionStateButton(
sessionState: _authgear.sessionState,
targetState: SessionState.authenticated,
label: "Open Settings",
onPressed: _unconfigured || _loading
? null
: () {
_onPressOpenSettings(context);
},
),
SessionStateButton(
sessionState: _authgear.sessionState,
targetState: SessionState.authenticated,
label: "Change Password",
onPressed: _unconfigured || _loading
? null
: () {
_onPressChangePassword(context);
},
),
SessionStateButton(
sessionState: _authgear.sessionState,
targetState: SessionState.authenticated,
label: "Show auth_time",
onPressed: _unconfigured || _loading
? null
: () {
_onPressShowAuthTime(context);
},
),
SessionStateButton(
sessionState: _authgear.sessionState,
targetState: SessionState.authenticated,
label: "Logout",
onPressed: _unconfigured || _loading
? null
: () {
_onPressLogout(context);
},
),
],
),
);
},
),
);
}
Future<void> _syncAuthgearState() async {
final isBiometricEnabled = await _authgear.isBiometricEnabled();
setState(() {
_isBiometricEnabled = isBiometricEnabled;
});
}
Future<void> _onPressAuthenticate(BuildContext context) async {
try {
setState(() {
_loading = true;
});
final userInfo = await _authgear.authenticate(
redirectURI: redirectURI,
page: _page,
colorScheme: _getColorScheme(context),
wechatRedirectURI: wechatRedirectURI,
authenticationFlowGroup: _authenticationFlowGroupController.text,
);
setState(() {
_userInfo = userInfo;
});
} catch (e) {
onError(context, e);
} finally {
setState(() {
_loading = false;
});
}
}
Future<void> _onPressAuthenticateAnonymously(BuildContext context) async {
try {
setState(() {
_loading = true;
});
final userInfo = await _authgear.authenticateAnonymously();
setState(() {
_userInfo = userInfo;
});
} catch (e) {
onError(context, e);
} finally {
setState(() {
_loading = false;
});
}
}
Future<void> _onPressPromoteAnonymousUser(BuildContext context) async {
try {
setState(() {
_loading = true;
});
final userInfo = await _authgear.promoteAnonymousUser(
redirectURI: redirectURI,
colorScheme: _getColorScheme(context),
wechatRedirectURI: wechatRedirectURI,
);
setState(() {
_userInfo = userInfo;
});
} catch (e) {
onError(context, e);
} finally {
setState(() {
_loading = false;
});
}
}
Future<void> _onPressAuthenticateBiometric(BuildContext context) async {
try {
setState(() {
_loading = true;
});
final userInfo = await _authgear.authenticateBiometric(
ios: ios,
android: android,
);
setState(() {
_userInfo = userInfo;
});
} catch (e) {
onError(context, e);
} finally {
setState(() {
_loading = false;
});
}
}
Future<void> _onPressReauthenticateWeb(BuildContext context) async {
try {
setState(() {
_loading = true;
});
await _authgear.refreshIDToken();
if (!_authgear.canReauthenticate) {
throw Exception("canReauthenticate returns false for the current user");
}
final userInfo = await _authgear.reauthenticate(
redirectURI: redirectURI,
wechatRedirectURI: wechatRedirectURI,
authenticationFlowGroup: _authenticationFlowGroupController.text,
);
setState(() {
_userInfo = userInfo;
});
} catch (e) {
onError(context, e);
} finally {
setState(() {
_loading = false;
});
}
}
Future<void> _onPressReauthenticate(BuildContext context) async {
try {
setState(() {
_loading = true;
});
await _authgear.refreshIDToken();
if (!_authgear.canReauthenticate) {
throw Exception("canReauthenticate returns false for the current user");
}
final userInfo = await _authgear.reauthenticate(
redirectURI: redirectURI,
colorScheme: _getColorScheme(context),
wechatRedirectURI: wechatRedirectURI,
biometricIOS: ios,
biometricAndroid: android,
);
setState(() {
_userInfo = userInfo;
});
} catch (e) {
onError(context, e);
} finally {
setState(() {
_loading = false;
});
}
}
Future<void> _onPressGetUserInfo(BuildContext context) async {
try {
setState(() {
_loading = true;
});
final userInfo = await _authgear.getUserInfo();
setState(() {
_userInfo = userInfo;
});
await showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return AlertDialog(
title: const Text("User Info"),
content:
Text(const JsonEncoder.withIndent(" ").convert(userInfo.raw)),
actions: [
TextButton(
child: const Text("OK"),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
} catch (e) {
onError(context, e);
} finally {
setState(() {
_loading = false;
});
}
}
Future<void> _onPressLogout(BuildContext context) async {
try {
setState(() {
_loading = true;
});
await _authgear.logout();
setState(() {
_userInfo = null;
});
} catch (e) {
onError(context, e);
} finally {
setState(() {
_loading = false;
});
}
}
Future<void> _onPressConfigure() async {
final endpoint = _endpointController.text;
final clientID = _clientIDController.text;
final authgear = Authgear(
endpoint: endpoint,
clientID: clientID,
isSsoEnabled: _isSsoEnabled,
tokenStorage: _useTransientTokenStorage ? TransientTokenStorage() : null,
uiImplementation: _useWebKitWebView
? WebKitWebViewUIImplementation(
options: WebKitWebViewUIImplementationOptions(
ios: WebKitWebViewUIImplementationOptionsIOS(
modalPresentationStyle: ModalPresentationStyle.fullScreen,
isInspectable: true,
),
),
)
: null,
sendWechatAuthRequest: _sendWechatAuthRequest,
);
_sub?.cancel();
await authgear.configure();
await _sharedPreferences.setString(
"authgear.endpoint",
endpoint,
);
await _sharedPreferences.setString(
"authgear.clientID",
clientID,
);
UserInfo? userInfo;
if (authgear.sessionState == SessionState.authenticated) {
userInfo = await authgear.getUserInfo();
}
setState(() {
_authgear = authgear;
_userInfo = userInfo;
_sub = _authgear.onSessionStateChange.listen((e) {
_syncAuthgearState();
});
_syncAuthgearState();
});
}
Future<void> _onPressOpenSettings(BuildContext context) async {
try {
setState(() {
_loading = true;
});
await _authgear.open(
page: SettingsPage.settings,
colorScheme: _getColorScheme(context),
wechatRedirectURI: wechatRedirectURI,
);
} catch (e) {
onError(context, e);
} finally {
setState(() {
_loading = false;
});
}
}
Future<void> _onPressChangePassword(BuildContext context) async {
try {
setState(() {
_loading = true;
});
await _authgear.changePassword(
redirectURI: redirectURI,
colorScheme: _getColorScheme(context),
wechatRedirectURI: wechatRedirectURI,
);
} catch (e) {
onError(context, e);
} finally {
setState(() {
_loading = false;
});
}
}
Future<void> _onPressShowAuthTime(BuildContext context) async {
showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return AlertDialog(
title: const Text("auth_time"),
content: Text("${_authgear.authTime}"),
actions: [
TextButton(
child: const Text("OK"),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
Future<void> _onPressEnableBiometric(BuildContext context) async {
try {
setState(() {
_loading = true;
});
await _authgear.checkBiometricSupported(
ios: ios,
android: android,
);
await _authgear.enableBiometric(
ios: ios,
android: android,
);
await _syncAuthgearState();
} catch (e) {
onError(context, e);
} finally {
setState(() {
_loading = false;
});
}
}
Future<void> _onPressDisableBiometric(BuildContext context) async {
try {
setState(() {
_loading = true;
});
await _authgear.disableBiometric();
await _syncAuthgearState();
} catch (e) {
onError(context, e);
} finally {
setState(() {
_loading = false;
});
}
}
Future<void> _sendWechatAuthRequest(String state) async {
try {
final code =
await _nativeMethodChannel.invokeMethod("sendWechatAuthRequest", {
"state": state,
});
await _authgear.wechatAuthCallback(state: state, code: code);
} on PlatformException catch (e) {
print("exception: $e");
}
}
void onError(BuildContext context, dynamic e) {
if (e is CancelException) {
return;
}
showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return AlertDialog(
title: const Text("Error"),
content: Text(_showError(e)),
actions: [
TextButton(
child: const Text("OK"),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
}