@@ -13,18 +13,18 @@ import 'package:tekartik_google_jsapi_picker/picker.dart';
13
13
import 'test_config.dart' ;
14
14
import 'test_setup.dart' ;
15
15
16
- GapiAuth2 gapiAuth;
17
- GooglePicker gpicker;
16
+ GapiAuth2 ? gapiAuth;
17
+ GooglePicker ? gpicker;
18
18
19
19
Storage storage = window.localStorage;
20
20
21
21
String storageKeyPref = 'com.tekartik.google_jsapi_picker_example' ;
22
22
23
- String storageGet (String key) {
23
+ String ? storageGet (String key) {
24
24
return storage['$storageKeyPref .$key ' ];
25
25
}
26
26
27
- void storageSet (String key, String value) {
27
+ void storageSet (String key, String ? value) {
28
28
var prefKey = '$storageKeyPref .$key ' ;
29
29
if (value == null ) {
30
30
storage.remove (prefKey);
@@ -39,12 +39,12 @@ String appMimeTypesKey = 'mime_types';
39
39
String selectFolderEnabledKey = 'select_folder_enabled' ;
40
40
String includeFoldersKey = 'include_folders' ;
41
41
42
- Element pickResult;
43
- String _authToken;
44
- InputElement mimeTypesInput;
42
+ Element ? pickResult;
43
+ String ? _authToken;
44
+ InputElement ? mimeTypesInput;
45
45
46
46
void _pick () {
47
- final mimeTypesText = mimeTypesInput.value;
47
+ final mimeTypesText = mimeTypesInput! .value! ;
48
48
storageSet (appMimeTypesKey, mimeTypesText);
49
49
50
50
final builder = PickerBuilder (gpicker);
@@ -59,12 +59,12 @@ void _pick() {
59
59
print ('includeFolders: $includeFolders ' );
60
60
// use docs view for folder
61
61
if (selectFolderEnabled || includeFolders) {
62
- final pickerDocsView = PickerDocsView (gpicker, gpicker.viewId.docs);
62
+ final pickerDocsView = PickerDocsView (gpicker! , gpicker! .viewId.docs);
63
63
pickerDocsView.selectFolderEnabled = true ;
64
64
pickerDocsView.includeFolders = true ;
65
65
pickerView = pickerDocsView;
66
66
} else {
67
- pickerView = PickerView (gpicker, gpicker.viewId.docs);
67
+ pickerView = PickerView (gpicker! , gpicker! .viewId.docs);
68
68
}
69
69
final mimeTypes = mimeTypesText.split (',' );
70
70
if (mimeTypes.isNotEmpty && mimeTypes[0 ].isNotEmpty) {
@@ -73,27 +73,27 @@ void _pick() {
73
73
74
74
builder.addView (pickerView);
75
75
76
- builder.developerKey = appOptions.developerKey;
76
+ builder.developerKey = appOptions! .developerKey;
77
77
builder.oauthToken = _authToken;
78
78
final uiPicker = builder.build ();
79
79
uiPicker.pick ().then ((PickerDataDocuments docs) {
80
- pickResult.innerHtml = docs.toString ();
80
+ pickResult! .innerHtml = docs.toString ();
81
81
82
82
//pickResult.innerHtml = docs[0].id;
83
83
});
84
84
}
85
85
86
86
void pickerMain (String authToken) {
87
- authorizeResult.innerHtml = 'Authorize token $authToken ' ;
87
+ authorizeResult! .innerHtml = 'Authorize token $authToken ' ;
88
88
print ('token: $authToken ' );
89
89
_authToken = authToken;
90
90
91
- final pickerForm = querySelector ('form.app-picker' );
91
+ final pickerForm = querySelector ('form.app-picker' )! ;
92
92
pickResult = pickerForm.querySelector ('.app-result' );
93
93
pickerForm.classes.remove ('hidden' );
94
94
mimeTypesInput =
95
- pickerForm.querySelector ('input#appInputMimeTypes' ) as InputElement ;
96
- final pickButton = pickerForm.querySelector ('button.app-pick' );
95
+ pickerForm.querySelector ('input#appInputMimeTypes' ) as InputElement ? ;
96
+ final pickButton = pickerForm.querySelector ('button.app-pick' )! ;
97
97
98
98
final selectFolderEnabledInput = pickerForm
99
99
.querySelector ('#appInputSelectFolderEnabled' ) as CheckboxInputElement ;
@@ -113,17 +113,17 @@ void pickerMain(String authToken) {
113
113
storageSet (includeFoldersKey, includeFoldersInput.checked.toString ());
114
114
});
115
115
116
- mimeTypesInput.value = storageGet (appMimeTypesKey);
116
+ mimeTypesInput! .value = storageGet (appMimeTypesKey);
117
117
118
118
pickButton.onClick.listen ((Event event) {
119
119
event.preventDefault ();
120
120
_pick ();
121
121
});
122
122
}
123
123
124
- Element authorizeResult;
125
- BrowserOAuth2Flow auth2flow;
126
- AppOptions appOptions;
124
+ Element ? authorizeResult;
125
+ BrowserOAuth2Flow ? auth2flow;
126
+ AppOptions ? appOptions;
127
127
final _setupLock = Lock ();
128
128
129
129
Future configSetup () async {
@@ -133,7 +133,7 @@ Future configSetup() async {
133
133
appOptions = await setup ();
134
134
135
135
void _errorSetup () {
136
- authorizeResult.innerText = '''
136
+ authorizeResult! .innerText = '''
137
137
ERROR: Missing clientId, clientSecret or developerKey
138
138
Create local.config.yaml from sample.local.config.yaml ($appOptions )''' ;
139
139
}
@@ -142,13 +142,13 @@ Create local.config.yaml from sample.local.config.yaml ($appOptions)''';
142
142
final clientSecret = appOptions? .clientSecret;
143
143
if (clientId? .isNotEmpty != true ||
144
144
clientSecret? .isNotEmpty != true ||
145
- appOptions.developerKey? .isNotEmpty != true ) {
145
+ appOptions! .developerKey? .isNotEmpty != true ) {
146
146
_errorSetup ();
147
147
return ;
148
148
}
149
149
150
150
var authClientId =
151
- ClientId (appOptions.clientId, appOptions.clientSecret);
151
+ ClientId (appOptions! .clientId! , appOptions! .clientSecret);
152
152
final scopes = < String > [GooglePicker .scopeDriveAppFile];
153
153
154
154
auth2flow? .close ();
@@ -158,19 +158,19 @@ Create local.config.yaml from sample.local.config.yaml ($appOptions)''';
158
158
}
159
159
}
160
160
161
- Future _authorize ({bool auto}) async {
161
+ Future _authorize ({bool ? auto}) async {
162
162
auto ?? = false ;
163
163
await configSetup ();
164
164
165
- var result = await auth2flow.runHybridFlow (immediate: auto);
165
+ var result = await auth2flow! .runHybridFlow (immediate: auto);
166
166
var oauthToken = result.credentials.accessToken.data;
167
167
pickerMain (oauthToken);
168
168
}
169
169
170
170
void authMain () {
171
- final authForm = querySelector ('form.app-auth' );
171
+ final authForm = querySelector ('form.app-auth' )! ;
172
172
authForm.classes.remove ('hidden' );
173
- final authorizeButton = authForm.querySelector ('button.app-authorize' );
173
+ final authorizeButton = authForm.querySelector ('button.app-authorize' )! ;
174
174
175
175
authorizeResult = authForm.querySelector ('.app-result' );
176
176
final autoAuthCheckbox =
@@ -193,24 +193,24 @@ void authMain() {
193
193
}
194
194
}
195
195
196
- Element loadGapiResult;
196
+ Element ? loadGapiResult;
197
197
198
198
Future _loadPicker () async {
199
- loadGapiResult.innerHtml = 'loading Gapi...' ;
199
+ loadGapiResult! .innerHtml = 'loading Gapi...' ;
200
200
try {
201
201
final gapi = await loadGapiPlatform ();
202
- loadGapiResult.innerHtml = 'loading GooglePicker...' ;
202
+ loadGapiResult! .innerHtml = 'loading GooglePicker...' ;
203
203
gpicker = await loadPicker (gapi);
204
- loadGapiResult.innerHtml = 'GooglePicker loaded' ;
204
+ loadGapiResult! .innerHtml = 'GooglePicker loaded' ;
205
205
} catch (e) {
206
- loadGapiResult.innerHtml = 'load failed $e ' ;
206
+ loadGapiResult! .innerHtml = 'load failed $e ' ;
207
207
rethrow ;
208
208
}
209
209
authMain ();
210
210
}
211
211
212
212
Future main () async {
213
- final loadGapiForm = querySelector ('form.app-gapi' );
213
+ final loadGapiForm = querySelector ('form.app-gapi' )! ;
214
214
loadGapiResult = loadGapiForm.querySelector ('.app-result' );
215
215
216
216
await await _loadPicker ();
0 commit comments