|
1 |
| -import 'package:apidash/providers/environment_providers.dart'; |
2 | 1 | import 'package:apidash_core/apidash_core.dart';
|
3 | 2 | import 'package:apidash/consts.dart';
|
4 |
| -import 'package:apidash/models/models.dart'; |
5 |
| -import 'package:flutter/material.dart'; |
6 |
| -import 'package:hooks_riverpod/hooks_riverpod.dart'; |
7 |
| -import 'package:insomnia_collection/models/insomnia_environment.dart'; |
8 |
| - |
9 |
| -List<EnvironmentVariableModel> createNewEnvironment(WidgetRef ref, InsomniaEnvironment environment) { |
10 |
| - // Step 1: Add a new environment |
11 |
| - ref.read(environmentsStateNotifierProvider.notifier).addEnvironment(); |
12 |
| - |
13 |
| - // Step 2: Get the ID of the newly created environment |
14 |
| - final newEnvironmentId = |
15 |
| - ref.read(selectedEnvironmentIdStateProvider.notifier).state; |
16 |
| - |
17 |
| - debugPrint('New id is $newEnvironmentId'); |
18 |
| - |
19 |
| - // Step 3: Update the new environment with a name and variables |
20 |
| - if (newEnvironmentId != null) { |
21 |
| - if (environment.resources == null || environment.resources!.isEmpty) { |
22 |
| - debugPrint('No env variables found'); |
23 |
| - return []; |
24 |
| - } |
25 |
| - List<EnvironmentVariableModel> variables = []; |
26 |
| - for (var env in environment.resources!) { |
27 |
| - variables.add(EnvironmentVariableModel( |
28 |
| - key: env.key, |
29 |
| - value: env.value, |
30 |
| - enabled: env.enabled ?? true, |
31 |
| - type: env.type == "secret" |
32 |
| - ? EnvironmentVariableType.secret |
33 |
| - : EnvironmentVariableType.variable, |
34 |
| - )); |
35 |
| - } |
36 |
| - ref.read(environmentsStateNotifierProvider.notifier).updateEnvironment( |
37 |
| - newEnvironmentId, |
38 |
| - name: environment.name ?? "Untitled", |
39 |
| - values: variables, |
40 |
| - ); |
41 |
| - return variables; |
42 |
| - } else { |
43 |
| - debugPrint('No env id found'); |
44 |
| - return []; |
45 |
| - } |
46 |
| -} |
47 | 3 |
|
48 | 4 | String getEnvironmentTitle(String? name) {
|
49 | 5 | if (name == null || name.trim() == "") {
|
|
0 commit comments