mirror of
https://github.com/foss42/apidash.git
synced 2025-12-01 18:28:25 +08:00
refactor: rename getTempFilePath to getDocumentsDirectoryFilePath for clarity
This commit is contained in:
@@ -5,98 +5,58 @@ import 'package:flutter/material.dart';
|
|||||||
|
|
||||||
class OAuth2Fields extends StatefulWidget {
|
class OAuth2Fields extends StatefulWidget {
|
||||||
final AuthModel? authData;
|
final AuthModel? authData;
|
||||||
|
|
||||||
final bool readOnly;
|
final bool readOnly;
|
||||||
|
|
||||||
final Function(AuthModel?)? updateAuth;
|
final Function(AuthModel?)? updateAuth;
|
||||||
|
|
||||||
const OAuth2Fields({
|
const OAuth2Fields({
|
||||||
super.key,
|
super.key,
|
||||||
required this.authData,
|
required this.authData,
|
||||||
this.updateAuth,
|
this.updateAuth,
|
||||||
this.readOnly = false,
|
this.readOnly = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<OAuth2Fields> createState() => _OAuth2FieldsState();
|
State<OAuth2Fields> createState() => _OAuth2FieldsState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _OAuth2FieldsState extends State<OAuth2Fields> {
|
class _OAuth2FieldsState extends State<OAuth2Fields> {
|
||||||
late OAuth2GrantType _grantType;
|
late OAuth2GrantType _grantType;
|
||||||
|
|
||||||
late TextEditingController _authorizationUrlController;
|
late TextEditingController _authorizationUrlController;
|
||||||
|
|
||||||
late TextEditingController _accessTokenUrlController;
|
late TextEditingController _accessTokenUrlController;
|
||||||
|
|
||||||
late TextEditingController _clientIdController;
|
late TextEditingController _clientIdController;
|
||||||
|
|
||||||
late TextEditingController _clientSecretController;
|
late TextEditingController _clientSecretController;
|
||||||
|
|
||||||
late TextEditingController _redirectUrlController;
|
late TextEditingController _redirectUrlController;
|
||||||
|
|
||||||
late TextEditingController _scopeController;
|
late TextEditingController _scopeController;
|
||||||
|
|
||||||
late TextEditingController _stateController;
|
late TextEditingController _stateController;
|
||||||
|
|
||||||
late String _codeChallengeMethod;
|
late String _codeChallengeMethod;
|
||||||
|
|
||||||
late TextEditingController _usernameController;
|
late TextEditingController _usernameController;
|
||||||
|
|
||||||
late TextEditingController _passwordController;
|
late TextEditingController _passwordController;
|
||||||
|
|
||||||
late TextEditingController _refreshTokenController;
|
late TextEditingController _refreshTokenController;
|
||||||
|
|
||||||
late TextEditingController _identityTokenController;
|
late TextEditingController _identityTokenController;
|
||||||
|
|
||||||
late TextEditingController _accessTokenController;
|
late TextEditingController _accessTokenController;
|
||||||
|
|
||||||
// late TextEditingController _headerPrefixController;
|
|
||||||
|
|
||||||
// late TextEditingController _audienceController;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
final oauth2 = widget.authData?.oauth2;
|
final oauth2 = widget.authData?.oauth2;
|
||||||
|
|
||||||
_grantType = oauth2?.grantType ?? OAuth2GrantType.authorizationCode;
|
_grantType = oauth2?.grantType ?? OAuth2GrantType.authorizationCode;
|
||||||
|
|
||||||
_authorizationUrlController =
|
_authorizationUrlController =
|
||||||
TextEditingController(text: oauth2?.authorizationUrl ?? '');
|
TextEditingController(text: oauth2?.authorizationUrl ?? '');
|
||||||
|
|
||||||
_accessTokenUrlController =
|
_accessTokenUrlController =
|
||||||
TextEditingController(text: oauth2?.accessTokenUrl ?? '');
|
TextEditingController(text: oauth2?.accessTokenUrl ?? '');
|
||||||
|
|
||||||
_clientIdController = TextEditingController(text: oauth2?.clientId ?? '');
|
_clientIdController = TextEditingController(text: oauth2?.clientId ?? '');
|
||||||
|
|
||||||
_clientSecretController =
|
_clientSecretController =
|
||||||
TextEditingController(text: oauth2?.clientSecret ?? '');
|
TextEditingController(text: oauth2?.clientSecret ?? '');
|
||||||
|
|
||||||
_redirectUrlController =
|
_redirectUrlController =
|
||||||
TextEditingController(text: oauth2?.redirectUrl ?? '');
|
TextEditingController(text: oauth2?.redirectUrl ?? '');
|
||||||
|
|
||||||
_scopeController = TextEditingController(text: oauth2?.scope ?? '');
|
_scopeController = TextEditingController(text: oauth2?.scope ?? '');
|
||||||
|
|
||||||
_stateController = TextEditingController(text: oauth2?.state ?? '');
|
_stateController = TextEditingController(text: oauth2?.state ?? '');
|
||||||
|
|
||||||
_usernameController = TextEditingController(text: oauth2?.username ?? '');
|
_usernameController = TextEditingController(text: oauth2?.username ?? '');
|
||||||
|
|
||||||
_passwordController = TextEditingController(text: oauth2?.password ?? '');
|
_passwordController = TextEditingController(text: oauth2?.password ?? '');
|
||||||
|
|
||||||
_refreshTokenController =
|
_refreshTokenController =
|
||||||
TextEditingController(text: oauth2?.refreshToken ?? '');
|
TextEditingController(text: oauth2?.refreshToken ?? '');
|
||||||
|
|
||||||
_identityTokenController =
|
_identityTokenController =
|
||||||
TextEditingController(text: oauth2?.identityToken ?? '');
|
TextEditingController(text: oauth2?.identityToken ?? '');
|
||||||
|
|
||||||
_accessTokenController =
|
_accessTokenController =
|
||||||
TextEditingController(text: oauth2?.accessToken ?? '');
|
TextEditingController(text: oauth2?.accessToken ?? '');
|
||||||
|
|
||||||
// _headerPrefixController = TextEditingController(text: oauth2?.headerPrefix ?? '');
|
|
||||||
|
|
||||||
// _audienceController = TextEditingController(text: oauth2?.audience ?? '');
|
|
||||||
|
|
||||||
_codeChallengeMethod = oauth2?.codeChallengeMethod ?? 'sha-256';
|
_codeChallengeMethod = oauth2?.codeChallengeMethod ?? 'sha-256';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,9 +69,7 @@ class _OAuth2FieldsState extends State<OAuth2Fields> {
|
|||||||
"Grant Type",
|
"Grant Type",
|
||||||
style: Theme.of(context).textTheme.labelLarge,
|
style: Theme.of(context).textTheme.labelLarge,
|
||||||
),
|
),
|
||||||
|
|
||||||
kVSpacer5,
|
kVSpacer5,
|
||||||
|
|
||||||
ADPopupMenu<OAuth2GrantType>(
|
ADPopupMenu<OAuth2GrantType>(
|
||||||
value: _grantType.displayType,
|
value: _grantType.displayType,
|
||||||
values: OAuth2GrantType.values.map((e) => (e, e.displayType)),
|
values: OAuth2GrantType.values.map((e) => (e, e.displayType)),
|
||||||
@@ -127,9 +85,7 @@ class _OAuth2FieldsState extends State<OAuth2Fields> {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
||||||
kVSpacer16,
|
kVSpacer16,
|
||||||
|
|
||||||
if (_shouldShowField(OAuth2Field.authorizationUrl))
|
if (_shouldShowField(OAuth2Field.authorizationUrl))
|
||||||
..._buildFieldWithSpacing(
|
..._buildFieldWithSpacing(
|
||||||
AuthTextField(
|
AuthTextField(
|
||||||
@@ -139,7 +95,6 @@ class _OAuth2FieldsState extends State<OAuth2Fields> {
|
|||||||
onChanged: (_) => _updateOAuth2(),
|
onChanged: (_) => _updateOAuth2(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
if (_shouldShowField(OAuth2Field.username))
|
if (_shouldShowField(OAuth2Field.username))
|
||||||
..._buildFieldWithSpacing(
|
..._buildFieldWithSpacing(
|
||||||
AuthTextField(
|
AuthTextField(
|
||||||
@@ -149,7 +104,6 @@ class _OAuth2FieldsState extends State<OAuth2Fields> {
|
|||||||
onChanged: (_) => _updateOAuth2(),
|
onChanged: (_) => _updateOAuth2(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
if (_shouldShowField(OAuth2Field.password))
|
if (_shouldShowField(OAuth2Field.password))
|
||||||
..._buildFieldWithSpacing(
|
..._buildFieldWithSpacing(
|
||||||
AuthTextField(
|
AuthTextField(
|
||||||
@@ -160,7 +114,6 @@ class _OAuth2FieldsState extends State<OAuth2Fields> {
|
|||||||
onChanged: (_) => _updateOAuth2(),
|
onChanged: (_) => _updateOAuth2(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
if (_shouldShowField(OAuth2Field.accessTokenUrl))
|
if (_shouldShowField(OAuth2Field.accessTokenUrl))
|
||||||
..._buildFieldWithSpacing(
|
..._buildFieldWithSpacing(
|
||||||
AuthTextField(
|
AuthTextField(
|
||||||
@@ -170,7 +123,6 @@ class _OAuth2FieldsState extends State<OAuth2Fields> {
|
|||||||
onChanged: (_) => _updateOAuth2(),
|
onChanged: (_) => _updateOAuth2(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
if (_shouldShowField(OAuth2Field.clientId))
|
if (_shouldShowField(OAuth2Field.clientId))
|
||||||
..._buildFieldWithSpacing(
|
..._buildFieldWithSpacing(
|
||||||
AuthTextField(
|
AuthTextField(
|
||||||
@@ -180,7 +132,6 @@ class _OAuth2FieldsState extends State<OAuth2Fields> {
|
|||||||
onChanged: (_) => _updateOAuth2(),
|
onChanged: (_) => _updateOAuth2(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
if (_shouldShowField(OAuth2Field.clientSecret))
|
if (_shouldShowField(OAuth2Field.clientSecret))
|
||||||
..._buildFieldWithSpacing(
|
..._buildFieldWithSpacing(
|
||||||
AuthTextField(
|
AuthTextField(
|
||||||
@@ -191,7 +142,6 @@ class _OAuth2FieldsState extends State<OAuth2Fields> {
|
|||||||
onChanged: (_) => _updateOAuth2(),
|
onChanged: (_) => _updateOAuth2(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
if (_shouldShowField(OAuth2Field.codeChallengeMethod)) ...[
|
if (_shouldShowField(OAuth2Field.codeChallengeMethod)) ...[
|
||||||
Text(
|
Text(
|
||||||
"Code Challenge Method",
|
"Code Challenge Method",
|
||||||
@@ -218,7 +168,6 @@ class _OAuth2FieldsState extends State<OAuth2Fields> {
|
|||||||
),
|
),
|
||||||
kVSpacer16,
|
kVSpacer16,
|
||||||
],
|
],
|
||||||
|
|
||||||
if (_shouldShowField(OAuth2Field.redirectUrl))
|
if (_shouldShowField(OAuth2Field.redirectUrl))
|
||||||
..._buildFieldWithSpacing(
|
..._buildFieldWithSpacing(
|
||||||
AuthTextField(
|
AuthTextField(
|
||||||
@@ -228,7 +177,6 @@ class _OAuth2FieldsState extends State<OAuth2Fields> {
|
|||||||
onChanged: (_) => _updateOAuth2(),
|
onChanged: (_) => _updateOAuth2(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
if (_shouldShowField(
|
if (_shouldShowField(
|
||||||
OAuth2Field.scope)) // Based on refined list, Scope is always shown
|
OAuth2Field.scope)) // Based on refined list, Scope is always shown
|
||||||
|
|
||||||
@@ -240,7 +188,6 @@ class _OAuth2FieldsState extends State<OAuth2Fields> {
|
|||||||
onChanged: (_) => _updateOAuth2(),
|
onChanged: (_) => _updateOAuth2(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
if (_shouldShowField(OAuth2Field.state))
|
if (_shouldShowField(OAuth2Field.state))
|
||||||
..._buildFieldWithSpacing(
|
..._buildFieldWithSpacing(
|
||||||
AuthTextField(
|
AuthTextField(
|
||||||
@@ -250,51 +197,8 @@ class _OAuth2FieldsState extends State<OAuth2Fields> {
|
|||||||
onChanged: (_) => _updateOAuth2(),
|
onChanged: (_) => _updateOAuth2(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
// if (_shouldShowField(OAuth2Field
|
|
||||||
|
|
||||||
// .headerPrefix))
|
|
||||||
|
|
||||||
// ..._buildFieldWithSpacing(
|
|
||||||
|
|
||||||
// AuthTextField(
|
|
||||||
|
|
||||||
// readOnly: widget.readOnly,
|
|
||||||
|
|
||||||
// controller: _headerPrefixController,
|
|
||||||
|
|
||||||
// hintText: "Header Prefix",
|
|
||||||
|
|
||||||
// onChanged: (_) => _updateOAuth2(),
|
|
||||||
|
|
||||||
// ),
|
|
||||||
|
|
||||||
// ),
|
|
||||||
|
|
||||||
// if (_shouldShowField(OAuth2Field
|
|
||||||
|
|
||||||
// .audience))
|
|
||||||
|
|
||||||
// ..._buildFieldWithSpacing(
|
|
||||||
|
|
||||||
// AuthTextField(
|
|
||||||
|
|
||||||
// readOnly: widget.readOnly,
|
|
||||||
|
|
||||||
// controller: _audienceController,
|
|
||||||
|
|
||||||
// hintText: "Audience",
|
|
||||||
|
|
||||||
// onChanged: (_) => _updateOAuth2(),
|
|
||||||
|
|
||||||
// ),
|
|
||||||
|
|
||||||
// ),
|
|
||||||
|
|
||||||
Divider(),
|
Divider(),
|
||||||
|
|
||||||
kVSpacer16,
|
kVSpacer16,
|
||||||
|
|
||||||
..._buildFieldWithSpacing(
|
..._buildFieldWithSpacing(
|
||||||
AuthTextField(
|
AuthTextField(
|
||||||
readOnly: widget.readOnly,
|
readOnly: widget.readOnly,
|
||||||
@@ -303,7 +207,6 @@ class _OAuth2FieldsState extends State<OAuth2Fields> {
|
|||||||
onChanged: (_) => _updateOAuth2(),
|
onChanged: (_) => _updateOAuth2(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
..._buildFieldWithSpacing(
|
..._buildFieldWithSpacing(
|
||||||
AuthTextField(
|
AuthTextField(
|
||||||
readOnly: widget.readOnly,
|
readOnly: widget.readOnly,
|
||||||
@@ -312,7 +215,6 @@ class _OAuth2FieldsState extends State<OAuth2Fields> {
|
|||||||
onChanged: (_) => _updateOAuth2(),
|
onChanged: (_) => _updateOAuth2(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
..._buildFieldWithSpacing(
|
..._buildFieldWithSpacing(
|
||||||
AuthTextField(
|
AuthTextField(
|
||||||
readOnly: widget.readOnly,
|
readOnly: widget.readOnly,
|
||||||
@@ -321,7 +223,6 @@ class _OAuth2FieldsState extends State<OAuth2Fields> {
|
|||||||
onChanged: (_) => _updateOAuth2(),
|
onChanged: (_) => _updateOAuth2(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
kVSpacer16,
|
kVSpacer16,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
@@ -340,8 +241,6 @@ class _OAuth2FieldsState extends State<OAuth2Fields> {
|
|||||||
OAuth2Field.clientId,
|
OAuth2Field.clientId,
|
||||||
OAuth2Field.clientSecret,
|
OAuth2Field.clientSecret,
|
||||||
OAuth2Field.scope,
|
OAuth2Field.scope,
|
||||||
OAuth2Field.headerPrefix,
|
|
||||||
OAuth2Field.audience,
|
|
||||||
OAuth2Field.refreshToken,
|
OAuth2Field.refreshToken,
|
||||||
OAuth2Field.identityToken,
|
OAuth2Field.identityToken,
|
||||||
OAuth2Field.accessToken,
|
OAuth2Field.accessToken,
|
||||||
@@ -374,36 +273,19 @@ class _OAuth2FieldsState extends State<OAuth2Fields> {
|
|||||||
void _updateOAuth2() {
|
void _updateOAuth2() {
|
||||||
final updatedOAuth2 = AuthOAuth2Model(
|
final updatedOAuth2 = AuthOAuth2Model(
|
||||||
grantType: _grantType,
|
grantType: _grantType,
|
||||||
|
|
||||||
authorizationUrl: _authorizationUrlController.text.trim(),
|
authorizationUrl: _authorizationUrlController.text.trim(),
|
||||||
|
|
||||||
clientId: _clientIdController.text.trim(),
|
clientId: _clientIdController.text.trim(),
|
||||||
|
|
||||||
accessTokenUrl: _accessTokenUrlController.text.trim(),
|
accessTokenUrl: _accessTokenUrlController.text.trim(),
|
||||||
|
|
||||||
clientSecret: _clientSecretController.text.trim(),
|
clientSecret: _clientSecretController.text.trim(),
|
||||||
|
|
||||||
codeChallengeMethod: _codeChallengeMethod,
|
codeChallengeMethod: _codeChallengeMethod,
|
||||||
|
|
||||||
redirectUrl: _redirectUrlController.text.trim(),
|
redirectUrl: _redirectUrlController.text.trim(),
|
||||||
|
|
||||||
scope: _scopeController.text.trim(),
|
scope: _scopeController.text.trim(),
|
||||||
|
|
||||||
state: _stateController.text.trim(),
|
state: _stateController.text.trim(),
|
||||||
|
|
||||||
username: _usernameController.text.trim(),
|
username: _usernameController.text.trim(),
|
||||||
|
|
||||||
password: _passwordController.text.trim(),
|
password: _passwordController.text.trim(),
|
||||||
|
|
||||||
refreshToken: _refreshTokenController.text.trim(),
|
refreshToken: _refreshTokenController.text.trim(),
|
||||||
|
|
||||||
identityToken: _identityTokenController.text.trim(),
|
identityToken: _identityTokenController.text.trim(),
|
||||||
|
|
||||||
accessToken: _accessTokenController.text.trim(),
|
accessToken: _accessTokenController.text.trim(),
|
||||||
|
|
||||||
// headerPrefix: _headerPrefixController.text.trim(),
|
|
||||||
|
|
||||||
// audience: _audienceController.text.trim(),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
widget.updateAuth?.call(
|
widget.updateAuth?.call(
|
||||||
@@ -421,65 +303,33 @@ class _OAuth2FieldsState extends State<OAuth2Fields> {
|
|||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_authorizationUrlController.dispose();
|
_authorizationUrlController.dispose();
|
||||||
|
|
||||||
_accessTokenUrlController.dispose();
|
_accessTokenUrlController.dispose();
|
||||||
|
|
||||||
_clientIdController.dispose();
|
_clientIdController.dispose();
|
||||||
|
|
||||||
_clientSecretController.dispose();
|
_clientSecretController.dispose();
|
||||||
|
|
||||||
_redirectUrlController.dispose();
|
_redirectUrlController.dispose();
|
||||||
|
|
||||||
_scopeController.dispose();
|
_scopeController.dispose();
|
||||||
|
|
||||||
_stateController.dispose();
|
_stateController.dispose();
|
||||||
|
|
||||||
_usernameController.dispose();
|
_usernameController.dispose();
|
||||||
|
|
||||||
_passwordController.dispose();
|
_passwordController.dispose();
|
||||||
|
|
||||||
_refreshTokenController.dispose();
|
_refreshTokenController.dispose();
|
||||||
|
|
||||||
_identityTokenController.dispose();
|
_identityTokenController.dispose();
|
||||||
|
|
||||||
_accessTokenController.dispose();
|
_accessTokenController.dispose();
|
||||||
|
|
||||||
// _headerPrefixController.dispose();
|
|
||||||
|
|
||||||
// _audienceController.dispose();
|
|
||||||
|
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum OAuth2Field {
|
enum OAuth2Field {
|
||||||
authorizationUrl,
|
authorizationUrl,
|
||||||
|
|
||||||
accessTokenUrl,
|
accessTokenUrl,
|
||||||
|
|
||||||
clientId,
|
clientId,
|
||||||
|
|
||||||
clientSecret,
|
clientSecret,
|
||||||
|
|
||||||
redirectUrl,
|
redirectUrl,
|
||||||
|
|
||||||
scope,
|
scope,
|
||||||
|
|
||||||
state,
|
state,
|
||||||
|
|
||||||
codeChallengeMethod,
|
codeChallengeMethod,
|
||||||
|
|
||||||
username,
|
username,
|
||||||
|
|
||||||
password,
|
password,
|
||||||
|
|
||||||
refreshToken,
|
refreshToken,
|
||||||
|
|
||||||
identityToken,
|
identityToken,
|
||||||
|
|
||||||
accessToken,
|
accessToken,
|
||||||
|
|
||||||
headerPrefix,
|
|
||||||
|
|
||||||
audience
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,9 +34,9 @@ Future<String?> getFileDownloadpath(String? name, String? ext) async {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String?> getTempFilePath(String? name, String? ext) async {
|
Future<String?> getDocumentsDirectoryFilePath(String name, String? ext) async {
|
||||||
final Directory tempDir = await getApplicationCacheDirectory();
|
final Directory tempDir = await getApplicationDocumentsDirectory();
|
||||||
name = name ?? getTempFileName();
|
name = name;
|
||||||
ext = (ext != null) ? ".$ext" : "";
|
ext = (ext != null) ? ".$ext" : "";
|
||||||
String path = '${tempDir.path}/$name$ext';
|
String path = '${tempDir.path}/$name$ext';
|
||||||
int num = 1;
|
int num = 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user