DropboxToken.fromJson constructor
DropboxToken.fromJson(
- Map<String, dynamic> json
)
Implementation
factory DropboxToken.fromJson(Map<String, dynamic> json) {
final dynamic expiresInValue = json['expires_in'];
DateTime expires;
if (expiresInValue is int) {
expires = DateTime.now().add(Duration(seconds: expiresInValue));
} else if (expiresInValue is String) {
// Handles the case where the expiration is already an ISO 8601 string from storage
expires = DateTime.parse(expiresInValue);
} else {
throw Exception("Invalid 'expires_in' format");
}
return DropboxToken(
accessToken: json['access_token'] as String,
refreshToken: json['refresh_token'] as String?,
tokenType: json['token_type'] as String,
expiresIn: expires,
);
}