mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 02:39:19 +08:00
feat: depreciate timeago
This commit is contained in:
@@ -1,5 +1,22 @@
|
|||||||
const kEmpty = '';
|
const kEmpty = '';
|
||||||
|
|
||||||
|
enum OAuth2Field {
|
||||||
|
authorizationUrl,
|
||||||
|
accessTokenUrl,
|
||||||
|
clientId,
|
||||||
|
clientSecret,
|
||||||
|
redirectUrl,
|
||||||
|
scope,
|
||||||
|
state,
|
||||||
|
codeChallengeMethod,
|
||||||
|
username,
|
||||||
|
password,
|
||||||
|
refreshToken,
|
||||||
|
identityToken,
|
||||||
|
accessToken,
|
||||||
|
clearSession,
|
||||||
|
}
|
||||||
|
|
||||||
// API Key Auth
|
// API Key Auth
|
||||||
const kApiKeyHeaderName = 'x-api-key';
|
const kApiKeyHeaderName = 'x-api-key';
|
||||||
const kAddToLocations = [
|
const kAddToLocations = [
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ import 'package:apidash_core/apidash_core.dart';
|
|||||||
import 'package:apidash_design_system/apidash_design_system.dart';
|
import 'package:apidash_design_system/apidash_design_system.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:timeago/timeago.dart' as timeago;
|
|
||||||
import '../common_widgets.dart';
|
import '../common_widgets.dart';
|
||||||
import 'consts.dart';
|
import 'consts.dart';
|
||||||
|
import 'utils.dart';
|
||||||
|
|
||||||
class OAuth2Fields extends ConsumerStatefulWidget {
|
class OAuth2Fields extends ConsumerStatefulWidget {
|
||||||
final AuthModel? authData;
|
final AuthModel? authData;
|
||||||
@@ -375,7 +375,7 @@ class _OAuth2FieldsState extends ConsumerState<OAuth2Fields> {
|
|||||||
if (_tokenExpiration != null) ...[
|
if (_tokenExpiration != null) ...[
|
||||||
const SizedBox(height: 4),
|
const SizedBox(height: 4),
|
||||||
Text(
|
Text(
|
||||||
_getExpirationText(),
|
getExpirationText(_tokenExpiration),
|
||||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||||
color: _tokenExpiration!.isBefore(DateTime.now())
|
color: _tokenExpiration!.isBefore(DateTime.now())
|
||||||
? Theme.of(context).colorScheme.error
|
? Theme.of(context).colorScheme.error
|
||||||
@@ -482,49 +482,4 @@ class _OAuth2FieldsState extends ConsumerState<OAuth2Fields> {
|
|||||||
_tokenExpiration = null;
|
_tokenExpiration = null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
String _getExpirationText() {
|
|
||||||
if (_tokenExpiration == null) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
final now = DateTime.now();
|
|
||||||
if (_tokenExpiration!.isBefore(now)) {
|
|
||||||
return "Token expired ${timeago.format(_tokenExpiration!, clock: now)}";
|
|
||||||
} else {
|
|
||||||
// For future times, we want to show "in X hours" instead of "X hours from now"
|
|
||||||
final duration = _tokenExpiration!.difference(now);
|
|
||||||
if (duration.inDays > 0) {
|
|
||||||
return "Token expires in ${duration.inDays} day${duration.inDays > 1 ? 's' : ''}";
|
|
||||||
} else if (duration.inHours > 0) {
|
|
||||||
return "Token expires in ${duration.inHours} hour${duration.inHours > 1 ? 's' : ''}";
|
|
||||||
} else if (duration.inMinutes > 0) {
|
|
||||||
return "Token expires in ${duration.inMinutes} minute${duration.inMinutes > 1 ? 's' : ''}";
|
|
||||||
} else {
|
|
||||||
return "Token expires in less than a minute";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enum OAuth2Field {
|
|
||||||
authorizationUrl,
|
|
||||||
accessTokenUrl,
|
|
||||||
clientId,
|
|
||||||
clientSecret,
|
|
||||||
redirectUrl,
|
|
||||||
scope,
|
|
||||||
state,
|
|
||||||
codeChallengeMethod,
|
|
||||||
username,
|
|
||||||
password,
|
|
||||||
refreshToken,
|
|
||||||
identityToken,
|
|
||||||
accessToken,
|
|
||||||
clearSession,
|
|
||||||
}
|
}
|
||||||
|
|||||||
22
lib/screens/common_widgets/auth/utils.dart
Normal file
22
lib/screens/common_widgets/auth/utils.dart
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
String getExpirationText(DateTime? tokenExpiration) {
|
||||||
|
if (tokenExpiration == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
final now = DateTime.now();
|
||||||
|
if (tokenExpiration.isBefore(now)) {
|
||||||
|
return "Token expired";
|
||||||
|
} else {
|
||||||
|
// For future times, we want to show "in X hours" instead of "X hours from now"
|
||||||
|
final duration = tokenExpiration.difference(now);
|
||||||
|
if (duration.inDays > 0) {
|
||||||
|
return "Token expires in ${duration.inDays} day${duration.inDays > 1 ? 's' : ''}";
|
||||||
|
} else if (duration.inHours > 0) {
|
||||||
|
return "Token expires in ${duration.inHours} hour${duration.inHours > 1 ? 's' : ''}";
|
||||||
|
} else if (duration.inMinutes > 0) {
|
||||||
|
return "Token expires in ${duration.inMinutes} minute${duration.inMinutes > 1 ? 's' : ''}";
|
||||||
|
} else {
|
||||||
|
return "Token expires in less than a minute";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1770,14 +1770,6 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.5"
|
version: "2.1.5"
|
||||||
timeago:
|
|
||||||
dependency: "direct main"
|
|
||||||
description:
|
|
||||||
name: timeago
|
|
||||||
sha256: b05159406a97e1cbb2b9ee4faa9fb096fe0e2dfcd8b08fcd2a00553450d3422e
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "3.7.1"
|
|
||||||
timing:
|
timing:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|||||||
@@ -64,7 +64,6 @@ dependencies:
|
|||||||
scrollable_positioned_list: ^0.3.8
|
scrollable_positioned_list: ^0.3.8
|
||||||
share_plus: ^10.1.4
|
share_plus: ^10.1.4
|
||||||
shared_preferences: ^2.5.2
|
shared_preferences: ^2.5.2
|
||||||
timeago: ^3.7.0
|
|
||||||
url_launcher: ^6.2.5
|
url_launcher: ^6.2.5
|
||||||
uuid: ^4.5.0
|
uuid: ^4.5.0
|
||||||
vector_graphics_compiler: ^1.1.9+1
|
vector_graphics_compiler: ^1.1.9+1
|
||||||
|
|||||||
Reference in New Issue
Block a user