ready method
Implementation
Future<bool> ready() async {
if(!await con.hasInternetAccess) return false;
try{
gsi ??= GoogleSignIn(scopes: [scope]);
bool authd = gsi!.currentUser != null;
if(kIsWeb && gsi!.currentUser != null){
authd = await gsi!.canAccessScopes([scope]);
}
if(!authd){
await gsi!.signInSilently();
if(!kIsWeb && gsi!.currentUser == null){
await gsi!.signIn();
}
if(kIsWeb && !await gsi!.canAccessScopes([scope])){
await gsi!.requestScopes([scope]);
}
}
}catch(e, stack){
if(e is PlatformException && e.code == "network_error"){
return false;
}
if(kDebugMode){
print("init:");
print("${e.toString()}\n${stack.toString()}");
}else if (onError != null){
onError!(e, stack);
}
return false;
}
var client = await gsi!.authenticatedClient().onError((e, stack) {
if(e is PlatformException && e.code == "network_error"){
return null;
}
if(kDebugMode){
print("get client:");
print("${e.toString()}\n${stack.toString()}");
}else if (onError != null){
onError!(e, stack);
}
return null;
});
if(client == null) return false;
api = DriveApi(client);
return true;
}