Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions lib/providers/collection_providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ class CollectionStateNotifier
ref.read(codePaneVisibleStateProvider.notifier).state = false;
final defaultUriScheme = ref.read(settingsProvider).defaultUriScheme;
final EnvironmentModel? originalEnvironmentModel =
ref.read(selectedEnvironmentModelProvider);
ref.read(activeEnvironmentModelProvider);

if (requestId == null || state == null) {
return;
Expand All @@ -281,10 +281,11 @@ class CollectionStateNotifier
return;
}

if (requestModel != null &&
Copy link
Contributor

@DenserMeerkat DenserMeerkat Jul 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 277

final EnvironmentModel? originalEnvironmentModel =
        ref.read(selectedEnvironmentModelProvider);

It should use activeEnvironmentIdStateProvider from settings_providers.dart to find the active EnvironmentModel and not selectedEnvironmentModelProvider from environment_providers.dart

using selectedEnvironmentModelProvider adds the variables to the wrong environment.

apidash.mp4

!requestModel.preRequestScript.isNullOrEmpty()) {
requestModel = await handlePreRequestScript(
requestModel,
RequestModel executionRequestModel = requestModel!.copyWith();

if (!requestModel.preRequestScript.isNullOrEmpty()) {
executionRequestModel = await handlePreRequestScript(
executionRequestModel,
originalEnvironmentModel,
(envModel, updatedValues) {
ref
Expand All @@ -298,9 +299,9 @@ class CollectionStateNotifier
);
}

APIType apiType = requestModel!.apiType;
APIType apiType = executionRequestModel.apiType;
HttpRequestModel substitutedHttpRequestModel =
getSubstitutedHttpRequestModel(requestModel.httpRequestModel!);
getSubstitutedHttpRequestModel(executionRequestModel.httpRequestModel!);

// set current model's isWorking to true and update state
var map = {...state!};
Expand Down
9 changes: 9 additions & 0 deletions lib/providers/environment_providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ final selectedEnvironmentModelProvider =
return selectedId != null ? environments![selectedId] : null;
});

final activeEnvironmentModelProvider = StateProvider<EnvironmentModel?>((ref) {
final activeId = ref.watch(activeEnvironmentIdStateProvider);
final environments = ref.watch(environmentsStateNotifierProvider);
if (activeId != null && environments != null) {
return environments[activeId];
}
return null;
});

final availableEnvironmentVariablesStateProvider =
StateProvider<Map<String, List<EnvironmentVariableModel>>>((ref) {
Map<String, List<EnvironmentVariableModel>> result = {};
Expand Down
7 changes: 5 additions & 2 deletions lib/screens/history/history_widgets/his_scripts_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class _ScriptsCodePaneState extends ConsumerState<HistoryScriptsTab> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
padding: kP6,
child: ADDropdownButton<int>(
value: _selectedTabIndex,
values: tabs,
Expand All @@ -75,7 +75,10 @@ class _ScriptsCodePaneState extends ConsumerState<HistoryScriptsTab> {
),
),
Expanded(
child: content[_selectedTabIndex],
child: Padding(
padding: kPt5o10,
child: content[_selectedTabIndex],
),
),
],
);
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/pre_post_script_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Future<RequestModel> handlePreRequestScript(
debugPrint(
"Warning: Pre-request script updated environment variables, but no active environment was selected to save them to.");
}
return requestModel;
return newRequestModel;
}
return newRequestModel;
}
Expand All @@ -71,7 +71,7 @@ Future<RequestModel> handlePostResponseScript(
) async {
final scriptResult = await executePostResponseScript(
currentRequestModel: requestModel,
activeEnvironment: originalEnvironmentModel?.toJson() ?? {},
activeEnvironment: originalEnvironmentModel?.toJson() ?? {"values": []},
);

final newRequestModel =
Expand Down