fix: state persistance upon api type switch

This commit is contained in:
Udhay-Adithya
2025-06-14 10:47:17 +05:30
parent 52a1feb0ee
commit a48d059422

View File

@@ -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(
authData?.copyWith(
type: APIAuthType.apiKey, type: APIAuthType.apiKey,
apikey: AuthApiKeyModel( apikey: AuthApiKeyModel(
key: keyController.text, key: keyController.text,
name: nameController.text, name: nameController.text,
location: newLocation, 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(
authData?.copyWith(
type: APIAuthType.apiKey, type: APIAuthType.apiKey,
apikey: AuthApiKeyModel( apikey: AuthApiKeyModel(
key: keyController.text.trim(), key: keyController.text.trim(),
name: nameController.text, name: nameController.text,
location: currentLocation, location: currentLocation,
), ),
)), ),
),
), ),
], ],
); );
@@ -381,7 +385,8 @@ class EditAuthType extends ConsumerWidget {
], ],
onChanged: (String? newAddTokenTo) { onChanged: (String? newAddTokenTo) {
if (newAddTokenTo != null) { if (newAddTokenTo != null) {
updateAuth(ApiAuthModel( updateAuth(
authData?.copyWith(
type: APIAuthType.jwt, type: APIAuthType.jwt,
jwt: AuthJwtModel( jwt: AuthJwtModel(
secret: jwtSecretController.text.trim(), secret: jwtSecretController.text.trim(),
@@ -393,7 +398,8 @@ class EditAuthType extends ConsumerWidget {
queryParamKey: jwtQueryParamKeyController.text.trim(), queryParamKey: jwtQueryParamKeyController.text.trim(),
header: jwtHeaderController.text.trim(), header: jwtHeaderController.text.trim(),
), ),
)); ),
);
} }
}, },
), ),
@@ -428,7 +434,8 @@ class EditAuthType extends ConsumerWidget {
}).toList(), }).toList(),
onChanged: (String? newAlgorithm) { onChanged: (String? newAlgorithm) {
if (newAlgorithm != null) { if (newAlgorithm != null) {
updateAuth(ApiAuthModel( updateAuth(
authData?.copyWith(
type: APIAuthType.jwt, type: APIAuthType.jwt,
jwt: AuthJwtModel( jwt: AuthJwtModel(
secret: jwtSecretController.text.trim(), secret: jwtSecretController.text.trim(),
@@ -440,7 +447,8 @@ class EditAuthType extends ConsumerWidget {
queryParamKey: jwtQueryParamKeyController.text.trim(), queryParamKey: jwtQueryParamKeyController.text.trim(),
header: jwtHeaderController.text.trim(), header: jwtHeaderController.text.trim(),
), ),
)); ),
);
} }
}, },
), ),
@@ -465,7 +473,8 @@ class EditAuthType extends ConsumerWidget {
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
), ),
), ),
onChanged: (value) => updateAuth(ApiAuthModel( onChanged: (value) => updateAuth(
authData?.copyWith(
type: APIAuthType.jwt, type: APIAuthType.jwt,
jwt: AuthJwtModel( jwt: AuthJwtModel(
secret: jwtSecretController.text.trim(), secret: jwtSecretController.text.trim(),
@@ -477,7 +486,8 @@ class EditAuthType extends ConsumerWidget {
queryParamKey: jwtQueryParamKeyController.text.trim(), queryParamKey: jwtQueryParamKeyController.text.trim(),
header: jwtHeaderController.text.trim(), header: jwtHeaderController.text.trim(),
), ),
)), ),
),
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
CheckboxListTile( CheckboxListTile(
@@ -491,7 +501,8 @@ 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(
authData?.copyWith(
type: APIAuthType.jwt, type: APIAuthType.jwt,
jwt: AuthJwtModel( jwt: AuthJwtModel(
secret: jwtSecretController.text.trim(), secret: jwtSecretController.text.trim(),
@@ -503,7 +514,8 @@ class EditAuthType extends ConsumerWidget {
queryParamKey: jwtQueryParamKeyController.text.trim(), queryParamKey: jwtQueryParamKeyController.text.trim(),
header: jwtHeaderController.text.trim(), header: jwtHeaderController.text.trim(),
), ),
)); ),
);
}, },
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
@@ -529,7 +541,8 @@ class EditAuthType extends ConsumerWidget {
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
), ),
), ),
onChanged: (value) => updateAuth(ApiAuthModel( onChanged: (value) => updateAuth(
authData?.copyWith(
type: APIAuthType.jwt, type: APIAuthType.jwt,
jwt: AuthJwtModel( jwt: AuthJwtModel(
secret: jwtSecretController.text.trim(), secret: jwtSecretController.text.trim(),
@@ -541,7 +554,8 @@ class EditAuthType extends ConsumerWidget {
queryParamKey: jwtQueryParamKeyController.text.trim(), queryParamKey: jwtQueryParamKeyController.text.trim(),
header: jwtHeaderController.text.trim(), header: jwtHeaderController.text.trim(),
), ),
)), ),
),
), ),
// const SizedBox(height: 16), // const SizedBox(height: 16),
// if (currentAddTokenTo == 'header') ...[ // if (currentAddTokenTo == 'header') ...[