/
main.dart
98 lines (87 loc) · 2.43 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
import 'dart:io';
import 'package:auth0_native_example/example_app.dart';
import 'package:flutter/material.dart';
import 'package:auth0_native/auth0_native.dart';
import 'package:native_resource/native_resource.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
const String audience = '';
const String demoEmail = '';
const String demoPhone = '';
final List<String> connections = <String>[
'google-oauth2',
'amazon',
'facebook',
];
const String emailConnection = 'email';
const String smsConnection = 'sms';
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: FutureBuilder<dynamic>(
future: readConfig().then((config) {
/// Need to initialize the Auth0 SDK first.
return Auth0Native()
.initialize(
config['clientId'],
config['domain'],
oidc: true,
loggingEnabled: true,
)
.then((value) => config);
}),
builder: (context, snapshot) {
if (snapshot.hasError) {
return Scaffold(
body: Center(child: Text('error: ${snapshot.error}')),
);
}
if (!snapshot.hasData) {
return Scaffold(
body: Center(child: Text('Getting ready')),
);
}
return ExampleApp(
audience: audience,
scheme: snapshot.data['scheme'],
connections: connections,
emailConnection: emailConnection,
smsConnection: smsConnection,
initialEmail: demoEmail,
initialPhone: demoPhone,
);
},
),
);
}
Future<Map<String, String>> readConfig() async {
return {
'clientId': await NativeResource().read(
androidResourceName: 'com_auth0_client_id',
iosPlistKey: 'ClientId',
iosPlistFile: 'Auth0',
),
'domain': await NativeResource().read(
androidResourceName: 'com_auth0_domain',
iosPlistKey: 'Domain',
iosPlistFile: 'Auth0',
),
'scheme': Platform.isAndroid
? await NativeResource().read(
androidResourceName: 'com_auth0_scheme',
iosPlistKey: null,
)
: '',
};
}
}