mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 10:49:49 +08:00
fix: state persistance upon api type switch
This commit is contained in:
@@ -54,9 +54,11 @@ class EditAuthType extends ConsumerWidget {
|
|||||||
);
|
);
|
||||||
}).toList(),
|
}).toList(),
|
||||||
onChanged: (APIAuthType? newType) {
|
onChanged: (APIAuthType? newType) {
|
||||||
|
final selectedRequest = ref.read(selectedRequestModelProvider);
|
||||||
if (newType != null) {
|
if (newType != null) {
|
||||||
ref.read(collectionStateNotifierProvider.notifier).update(
|
ref.read(collectionStateNotifierProvider.notifier).update(
|
||||||
authData: currentAuthData?.copyWith(type: newType) ??
|
authData: selectedRequest?.authData
|
||||||
|
?.copyWith(type: newType) ??
|
||||||
ApiAuthModel(type: newType),
|
ApiAuthModel(type: newType),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -75,7 +77,7 @@ class EditAuthType extends ConsumerWidget {
|
|||||||
WidgetRef ref,
|
WidgetRef ref,
|
||||||
ApiAuthModel? authData,
|
ApiAuthModel? authData,
|
||||||
) {
|
) {
|
||||||
void updateAuth(ApiAuthModel model) {
|
void updateAuth(ApiAuthModel? model) {
|
||||||
ref.read(collectionStateNotifierProvider.notifier).update(
|
ref.read(collectionStateNotifierProvider.notifier).update(
|
||||||
authData: model,
|
authData: model,
|
||||||
);
|
);
|
||||||
@@ -114,15 +116,13 @@ class EditAuthType extends ConsumerWidget {
|
|||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
onChanged: (value) => updateAuth(
|
onChanged: (value) => updateAuth(authData?.copyWith(
|
||||||
ApiAuthModel(
|
type: APIAuthType.basic,
|
||||||
type: APIAuthType.basic,
|
basic: AuthBasicAuthModel(
|
||||||
basic: AuthBasicAuthModel(
|
username: usernameController.text.trim(),
|
||||||
username: usernameController.text.trim(),
|
password: passwordController.text.trim(),
|
||||||
password: passwordController.text.trim(),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
)),
|
||||||
),
|
),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: 16,
|
height: 16,
|
||||||
@@ -151,7 +151,7 @@ class EditAuthType extends ConsumerWidget {
|
|||||||
),
|
),
|
||||||
obscureText: true,
|
obscureText: true,
|
||||||
onChanged: (value) => updateAuth(
|
onChanged: (value) => updateAuth(
|
||||||
ApiAuthModel(
|
authData?.copyWith(
|
||||||
type: APIAuthType.basic,
|
type: APIAuthType.basic,
|
||||||
basic: AuthBasicAuthModel(
|
basic: AuthBasicAuthModel(
|
||||||
username: usernameController.text.trim(),
|
username: usernameController.text.trim(),
|
||||||
@@ -193,7 +193,7 @@ class EditAuthType extends ConsumerWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
onChanged: (value) => updateAuth(
|
onChanged: (value) => updateAuth(
|
||||||
ApiAuthModel(
|
authData?.copyWith(
|
||||||
type: APIAuthType.bearer,
|
type: APIAuthType.bearer,
|
||||||
bearer: AuthBearerModel(token: tokenController.text.trim()),
|
bearer: AuthBearerModel(token: tokenController.text.trim()),
|
||||||
),
|
),
|
||||||
@@ -246,14 +246,16 @@ class EditAuthType extends ConsumerWidget {
|
|||||||
],
|
],
|
||||||
onChanged: (String? newLocation) {
|
onChanged: (String? newLocation) {
|
||||||
if (newLocation != null) {
|
if (newLocation != null) {
|
||||||
updateAuth(ApiAuthModel(
|
updateAuth(
|
||||||
type: APIAuthType.apiKey,
|
authData?.copyWith(
|
||||||
apikey: AuthApiKeyModel(
|
type: APIAuthType.apiKey,
|
||||||
key: keyController.text,
|
apikey: AuthApiKeyModel(
|
||||||
name: nameController.text,
|
key: keyController.text,
|
||||||
location: newLocation,
|
name: nameController.text,
|
||||||
|
location: newLocation,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
));
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@@ -281,7 +283,7 @@ class EditAuthType extends ConsumerWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
onChanged: (value) => updateAuth(
|
onChanged: (value) => updateAuth(
|
||||||
ApiAuthModel(
|
authData?.copyWith(
|
||||||
type: APIAuthType.apiKey,
|
type: APIAuthType.apiKey,
|
||||||
apikey: AuthApiKeyModel(
|
apikey: AuthApiKeyModel(
|
||||||
key: keyController.text,
|
key: keyController.text,
|
||||||
@@ -314,14 +316,16 @@ class EditAuthType extends ConsumerWidget {
|
|||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
onChanged: (value) => updateAuth(ApiAuthModel(
|
onChanged: (value) => updateAuth(
|
||||||
type: APIAuthType.apiKey,
|
authData?.copyWith(
|
||||||
apikey: AuthApiKeyModel(
|
type: APIAuthType.apiKey,
|
||||||
key: keyController.text.trim(),
|
apikey: AuthApiKeyModel(
|
||||||
name: nameController.text,
|
key: keyController.text.trim(),
|
||||||
location: currentLocation,
|
name: nameController.text,
|
||||||
|
location: currentLocation,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
@@ -381,19 +385,21 @@ class EditAuthType extends ConsumerWidget {
|
|||||||
],
|
],
|
||||||
onChanged: (String? newAddTokenTo) {
|
onChanged: (String? newAddTokenTo) {
|
||||||
if (newAddTokenTo != null) {
|
if (newAddTokenTo != null) {
|
||||||
updateAuth(ApiAuthModel(
|
updateAuth(
|
||||||
type: APIAuthType.jwt,
|
authData?.copyWith(
|
||||||
jwt: AuthJwtModel(
|
type: APIAuthType.jwt,
|
||||||
secret: jwtSecretController.text.trim(),
|
jwt: AuthJwtModel(
|
||||||
payload: jwtPayloadController.text.trim(),
|
secret: jwtSecretController.text.trim(),
|
||||||
addTokenTo: newAddTokenTo,
|
payload: jwtPayloadController.text.trim(),
|
||||||
algorithm: currentAlgorithm,
|
addTokenTo: newAddTokenTo,
|
||||||
isSecretBase64Encoded: isSecretBase64Encoded,
|
algorithm: currentAlgorithm,
|
||||||
headerPrefix: jwtHeaderPrefixController.text.trim(),
|
isSecretBase64Encoded: isSecretBase64Encoded,
|
||||||
queryParamKey: jwtQueryParamKeyController.text.trim(),
|
headerPrefix: jwtHeaderPrefixController.text.trim(),
|
||||||
header: jwtHeaderController.text.trim(),
|
queryParamKey: jwtQueryParamKeyController.text.trim(),
|
||||||
|
header: jwtHeaderController.text.trim(),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
));
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@@ -428,19 +434,21 @@ class EditAuthType extends ConsumerWidget {
|
|||||||
}).toList(),
|
}).toList(),
|
||||||
onChanged: (String? newAlgorithm) {
|
onChanged: (String? newAlgorithm) {
|
||||||
if (newAlgorithm != null) {
|
if (newAlgorithm != null) {
|
||||||
updateAuth(ApiAuthModel(
|
updateAuth(
|
||||||
type: APIAuthType.jwt,
|
authData?.copyWith(
|
||||||
jwt: AuthJwtModel(
|
type: APIAuthType.jwt,
|
||||||
secret: jwtSecretController.text.trim(),
|
jwt: AuthJwtModel(
|
||||||
payload: jwtPayloadController.text.trim(),
|
secret: jwtSecretController.text.trim(),
|
||||||
addTokenTo: currentAddTokenTo,
|
payload: jwtPayloadController.text.trim(),
|
||||||
algorithm: newAlgorithm,
|
addTokenTo: currentAddTokenTo,
|
||||||
isSecretBase64Encoded: isSecretBase64Encoded,
|
algorithm: newAlgorithm,
|
||||||
headerPrefix: jwtHeaderPrefixController.text.trim(),
|
isSecretBase64Encoded: isSecretBase64Encoded,
|
||||||
queryParamKey: jwtQueryParamKeyController.text.trim(),
|
headerPrefix: jwtHeaderPrefixController.text.trim(),
|
||||||
header: jwtHeaderController.text.trim(),
|
queryParamKey: jwtQueryParamKeyController.text.trim(),
|
||||||
|
header: jwtHeaderController.text.trim(),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
));
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@@ -465,19 +473,21 @@ class EditAuthType extends ConsumerWidget {
|
|||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
onChanged: (value) => updateAuth(ApiAuthModel(
|
onChanged: (value) => updateAuth(
|
||||||
type: APIAuthType.jwt,
|
authData?.copyWith(
|
||||||
jwt: AuthJwtModel(
|
type: APIAuthType.jwt,
|
||||||
secret: jwtSecretController.text.trim(),
|
jwt: AuthJwtModel(
|
||||||
payload: jwtPayloadController.text.trim(),
|
secret: jwtSecretController.text.trim(),
|
||||||
addTokenTo: currentAddTokenTo,
|
payload: jwtPayloadController.text.trim(),
|
||||||
algorithm: currentAlgorithm,
|
addTokenTo: currentAddTokenTo,
|
||||||
isSecretBase64Encoded: isSecretBase64Encoded,
|
algorithm: currentAlgorithm,
|
||||||
headerPrefix: jwtHeaderPrefixController.text.trim(),
|
isSecretBase64Encoded: isSecretBase64Encoded,
|
||||||
queryParamKey: jwtQueryParamKeyController.text.trim(),
|
headerPrefix: jwtHeaderPrefixController.text.trim(),
|
||||||
header: jwtHeaderController.text.trim(),
|
queryParamKey: jwtQueryParamKeyController.text.trim(),
|
||||||
|
header: jwtHeaderController.text.trim(),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
CheckboxListTile(
|
CheckboxListTile(
|
||||||
@@ -491,19 +501,21 @@ class EditAuthType extends ConsumerWidget {
|
|||||||
contentPadding: EdgeInsets.zero,
|
contentPadding: EdgeInsets.zero,
|
||||||
controlAffinity: ListTileControlAffinity.leading,
|
controlAffinity: ListTileControlAffinity.leading,
|
||||||
onChanged: (bool? value) {
|
onChanged: (bool? value) {
|
||||||
updateAuth(ApiAuthModel(
|
updateAuth(
|
||||||
type: APIAuthType.jwt,
|
authData?.copyWith(
|
||||||
jwt: AuthJwtModel(
|
type: APIAuthType.jwt,
|
||||||
secret: jwtSecretController.text.trim(),
|
jwt: AuthJwtModel(
|
||||||
payload: jwtPayloadController.text.trim(),
|
secret: jwtSecretController.text.trim(),
|
||||||
addTokenTo: currentAddTokenTo,
|
payload: jwtPayloadController.text.trim(),
|
||||||
algorithm: currentAlgorithm,
|
addTokenTo: currentAddTokenTo,
|
||||||
isSecretBase64Encoded: value ?? false,
|
algorithm: currentAlgorithm,
|
||||||
headerPrefix: jwtHeaderPrefixController.text.trim(),
|
isSecretBase64Encoded: value ?? false,
|
||||||
queryParamKey: jwtQueryParamKeyController.text.trim(),
|
headerPrefix: jwtHeaderPrefixController.text.trim(),
|
||||||
header: jwtHeaderController.text.trim(),
|
queryParamKey: jwtQueryParamKeyController.text.trim(),
|
||||||
|
header: jwtHeaderController.text.trim(),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
));
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
@@ -529,19 +541,21 @@ class EditAuthType extends ConsumerWidget {
|
|||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
onChanged: (value) => updateAuth(ApiAuthModel(
|
onChanged: (value) => updateAuth(
|
||||||
type: APIAuthType.jwt,
|
authData?.copyWith(
|
||||||
jwt: AuthJwtModel(
|
type: APIAuthType.jwt,
|
||||||
secret: jwtSecretController.text.trim(),
|
jwt: AuthJwtModel(
|
||||||
payload: jwtPayloadController.text.trim(),
|
secret: jwtSecretController.text.trim(),
|
||||||
addTokenTo: currentAddTokenTo,
|
payload: jwtPayloadController.text.trim(),
|
||||||
algorithm: currentAlgorithm,
|
addTokenTo: currentAddTokenTo,
|
||||||
isSecretBase64Encoded: isSecretBase64Encoded,
|
algorithm: currentAlgorithm,
|
||||||
headerPrefix: jwtHeaderPrefixController.text.trim(),
|
isSecretBase64Encoded: isSecretBase64Encoded,
|
||||||
queryParamKey: jwtQueryParamKeyController.text.trim(),
|
headerPrefix: jwtHeaderPrefixController.text.trim(),
|
||||||
header: jwtHeaderController.text.trim(),
|
queryParamKey: jwtQueryParamKeyController.text.trim(),
|
||||||
|
header: jwtHeaderController.text.trim(),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)),
|
),
|
||||||
),
|
),
|
||||||
// const SizedBox(height: 16),
|
// const SizedBox(height: 16),
|
||||||
// if (currentAddTokenTo == 'header') ...[
|
// if (currentAddTokenTo == 'header') ...[
|
||||||
|
|||||||
Reference in New Issue
Block a user