-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.dart
108 lines (99 loc) · 3.65 KB
/
app.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
import 'package:argyle_link_flutter/account_data.dart';
import 'package:argyle_link_flutter/argyle_link.dart';
import 'package:argyle_link_flutter/form_data.dart';
import 'package:argyle_link_flutter/link_config.dart';
import 'package:flutter/material.dart';
import 'theme.dart';
class App extends StatefulWidget {
const App({Key? key}) : super(key: key);
@override
State<App> createState() => _AppState();
}
class _AppState extends State<App> {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primarySwatch: Palette.brandColor,
),
home: Scaffold(
appBar: AppBar(
title: const Text('📱️ Argyle Link SDK'),
),
body: Container(
alignment: AlignmentDirectional.center,
child: ElevatedButton(
onPressed: () {
startArgyleSdk();
},
child: const Text('Start Argyle SDK'),
)
),
),
);
}
startArgyleSdk() {
final config = LinkConfig(
userToken: 'YOUR_USER_TOKEN', // Should be fetched and provided by your own backend API https://argyle.com/docs/api-reference/users
sandbox: true,
// accountId: 'USER_ACCOUNT_ID', // Specify to take the user directly to the account
// flowId: '00000000', // Specify to use flows https://argyle.com/docs/console/flows
// ddsConfig: 'YOUR_DDS_CONFIG', // Specify to use deposit switching https://argyle.com/docs/workflows/deposit-switching
// items: ['item_000014039', 'item_000025742'], // Specify to limit search to the specified items only
);
configCallbacks(config);
ArgyleLink.start(config);
}
configCallbacks(LinkConfig config) {
config.onTokenExpired = (handler) {
const newToken = 'YOUR_NEW_TOKEN';
handler(newToken);
};
config.onAccountCreated = (accountData) =>
print('onAccountCreated: $accountData');
config.onAccountConnected = (accountData) =>
printAccountData('onAccountConnected', accountData);
config.onAccountRemoved = (accountData) =>
printAccountData('onAccountRemoved', accountData);
config.onAccountError = (accountData) =>
printAccountData('onAccountError', accountData);
config.onDDSSuccess = (accountData) =>
printAccountData('onDDSSuccess', accountData);
config.onDDSError = (accountData) =>
printAccountData('onDDSError', accountData);
config.onFormSubmitted = (formData) =>
printFormData('onFormSubmitted', formData);
config.onDocumentsSubmitted = (formData) =>
printFormData('onDocumentsSubmitted', formData);
config.onCantFindItemClicked = (term) =>
print('onCantFindItemClicked(${term})');
config.onError = (linkError) => print(
'onError(\n'
'\terrorType: ${linkError.errorType.name}\n'
'\terrorMessage: ${linkError.errorMessage}\n'
'${linkError.errorDetails != null ? '\terrorDetails: ${linkError.errorDetails}\n' : ''}'
')',
);
config.onClose = () => print('onClose');
config.onUiEvent = (uiEvent) {
final props = uiEvent.properties?.entries
.map((e) => '\t\t${e.key}: ${e.value}')
.join('\n');
print(
'onUIEvent(\n'
'\tname: ${uiEvent.name}\n'
'\tproperties:\n$props\n'
')',
);
};
}
printAccountData(String callbackName, AccountData accountData) {
print('$callbackName: accountId: ${accountData.accountId} '
'userId: ${accountData.userId} '
'itemId: ${accountData.itemId}');
}
printFormData(String callbackName, FormData formData) {
print('$callbackName: accountId: ${formData.accountId} '
'userId: ${formData.userId}');
}
}