Skip to content

Commit 3a7ae71

Browse files
committed
feat: automatic row adding
1 parent 0b66939 commit 3a7ae71

File tree

3 files changed

+68
-112
lines changed

3 files changed

+68
-112
lines changed

lib/screens/home_page/editor_pane/details_card/request_pane/request_form_data.dart

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class _FormDataBodyState extends ConsumerState<FormDataWidget> {
2727
@override
2828
Widget build(BuildContext context) {
2929
final selectedId = ref.watch(selectedIdStateProvider);
30+
ref.watch(selectedRequestModelProvider
31+
.select((value) => value?.requestFormDataList?.length));
3032
var formRows = ref.read(selectedRequestModelProvider)?.requestFormDataList;
3133
rows =
3234
formRows == null || formRows.isEmpty ? [kFormDataEmptyModel] : formRows;
@@ -47,18 +49,21 @@ class _FormDataBodyState extends ConsumerState<FormDataWidget> {
4749
initialValue: rows[idx].name,
4850
hintText: " Add Key",
4951
onChanged: (value) {
50-
rows[idx] = rows[idx].copyWith(
51-
name: value,
52-
);
52+
rows[idx] = rows[idx].copyWith(name: value);
53+
if (idx == rows.length - 1) rows.add(kFormDataEmptyModel);
5354
_onFieldChange(selectedId!);
5455
},
5556
colorScheme: Theme.of(context).colorScheme,
5657
formDataType: rows[idx].type,
5758
onFormDataTypeChanged: (value) {
59+
bool hasChanged = rows[idx].type != value;
5860
rows[idx] = rows[idx].copyWith(
5961
type: value ?? FormDataType.text,
6062
);
6163
rows[idx] = rows[idx].copyWith(value: "");
64+
if (idx == rows.length - 1 && hasChanged) {
65+
rows.add(kFormDataEmptyModel);
66+
}
6267
setState(() {});
6368
_onFieldChange(selectedId!);
6469
},
@@ -137,6 +142,7 @@ class _FormDataBodyState extends ConsumerState<FormDataWidget> {
137142
hintText: " Add Value",
138143
onChanged: (value) {
139144
rows[idx] = rows[idx].copyWith(value: value);
145+
if (idx == rows.length - 1) rows.add(kFormDataEmptyModel);
140146
_onFieldChange(selectedId!);
141147
},
142148
colorScheme: Theme.of(context).colorScheme,
@@ -169,45 +175,22 @@ class _FormDataBodyState extends ConsumerState<FormDataWidget> {
169175
),
170176
],
171177
);
172-
return Stack(
173-
children: [
174-
Container(
175-
decoration: BoxDecoration(
176-
color: Theme.of(context).colorScheme.background,
177-
borderRadius: kBorderRadius12,
178-
),
179-
margin: kP10,
180-
child: Column(
181-
children: [
182-
Expanded(
183-
child: DaviTheme(
184-
data: kTableThemeData,
185-
child: Davi<FormDataModel>(daviModelRows),
186-
),
187-
),
188-
],
189-
),
190-
),
191-
Align(
192-
alignment: Alignment.bottomCenter,
193-
child: Padding(
194-
padding: const EdgeInsets.only(bottom: 30),
195-
child: ElevatedButton.icon(
196-
onPressed: () {
197-
setState(() {
198-
rows.add(kFormDataEmptyModel);
199-
});
200-
_onFieldChange(selectedId!);
201-
},
202-
icon: const Icon(Icons.add),
203-
label: const Text(
204-
"Add Form Data",
205-
style: kTextStyleButton,
206-
),
178+
return Container(
179+
decoration: BoxDecoration(
180+
color: Theme.of(context).colorScheme.background,
181+
borderRadius: kBorderRadius12,
182+
),
183+
margin: kP10,
184+
child: Column(
185+
children: [
186+
Expanded(
187+
child: DaviTheme(
188+
data: kTableThemeData,
189+
child: Davi<FormDataModel>(daviModelRows),
207190
),
208191
),
209-
),
210-
],
192+
],
193+
),
211194
);
212195
}
213196

lib/screens/home_page/editor_pane/details_card/request_pane/request_headers.dart

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,12 @@ class EditRequestHeadersState extends ConsumerState<EditRequestHeaders> {
8181
initialValue: rows[idx].name,
8282
hintText: "Add Header Name",
8383
onChanged: (value) {
84+
isRowEnabledList[idx] = true;
8485
rows[idx] = rows[idx].copyWith(name: value);
86+
if (idx == rows.length - 1) {
87+
rows.add(kNameValueEmptyModel);
88+
isRowEnabledList.add(true);
89+
}
8590
_onFieldChange(selectedId!);
8691
},
8792
colorScheme: Theme.of(context).colorScheme,
@@ -109,6 +114,10 @@ class EditRequestHeadersState extends ConsumerState<EditRequestHeaders> {
109114
hintText: " Add Header Value",
110115
onChanged: (value) {
111116
rows[idx] = rows[idx].copyWith(value: value);
117+
if (idx == rows.length - 1) {
118+
rows.add(kNameValueEmptyModel);
119+
isRowEnabledList.add(true);
120+
}
112121
_onFieldChange(selectedId!);
113122
},
114123
colorScheme: Theme.of(context).colorScheme,
@@ -144,44 +153,22 @@ class EditRequestHeadersState extends ConsumerState<EditRequestHeaders> {
144153
),
145154
],
146155
);
147-
return Stack(
148-
children: [
149-
Container(
150-
decoration: BoxDecoration(
151-
color: Theme.of(context).colorScheme.background,
152-
borderRadius: kBorderRadius12,
153-
),
154-
margin: kP10,
155-
child: Column(
156-
children: [
157-
Expanded(
158-
child: DaviTheme(
159-
data: kTableThemeData,
160-
child: Davi<NameValueModel>(model),
161-
),
162-
),
163-
],
164-
),
165-
),
166-
Align(
167-
alignment: Alignment.bottomCenter,
168-
child: Padding(
169-
padding: const EdgeInsets.only(bottom: 30),
170-
child: ElevatedButton.icon(
171-
onPressed: () {
172-
rows.add(kNameValueEmptyModel);
173-
isRowEnabledList.add(true);
174-
_onFieldChange(selectedId!);
175-
},
176-
icon: const Icon(Icons.add),
177-
label: const Text(
178-
"Add Header",
179-
style: kTextStyleButton,
180-
),
156+
return Container(
157+
decoration: BoxDecoration(
158+
color: Theme.of(context).colorScheme.background,
159+
borderRadius: kBorderRadius12,
160+
),
161+
margin: kP10,
162+
child: Column(
163+
children: [
164+
Expanded(
165+
child: DaviTheme(
166+
data: kTableThemeData,
167+
child: Davi<NameValueModel>(model),
181168
),
182169
),
183-
),
184-
],
170+
],
171+
),
185172
);
186173
}
187174
}

lib/screens/home_page/editor_pane/details_card/request_pane/request_params.dart

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ class EditRequestURLParamsState extends ConsumerState<EditRequestURLParams> {
8383
hintText: "Add URL Parameter",
8484
onChanged: (value) {
8585
rows[idx] = rows[idx].copyWith(name: value);
86+
if (idx == rows.length - 1) {
87+
rows.add(kNameValueEmptyModel);
88+
isRowEnabledList.add(true);
89+
}
8690
_onFieldChange(selectedId!);
8791
},
8892
colorScheme: Theme.of(context).colorScheme,
@@ -110,6 +114,10 @@ class EditRequestURLParamsState extends ConsumerState<EditRequestURLParams> {
110114
hintText: "Add Value",
111115
onChanged: (value) {
112116
rows[idx] = rows[idx].copyWith(value: value);
117+
if (idx == rows.length - 1) {
118+
rows.add(kNameValueEmptyModel);
119+
isRowEnabledList.add(true);
120+
}
113121
_onFieldChange(selectedId!);
114122
},
115123
colorScheme: Theme.of(context).colorScheme,
@@ -145,44 +153,22 @@ class EditRequestURLParamsState extends ConsumerState<EditRequestURLParams> {
145153
),
146154
],
147155
);
148-
return Stack(
149-
children: [
150-
Container(
151-
decoration: BoxDecoration(
152-
color: Theme.of(context).colorScheme.background,
153-
borderRadius: kBorderRadius12,
154-
),
155-
margin: kP10,
156-
child: Column(
157-
children: [
158-
Expanded(
159-
child: DaviTheme(
160-
data: kTableThemeData,
161-
child: Davi<NameValueModel>(model),
162-
),
163-
),
164-
],
165-
),
166-
),
167-
Align(
168-
alignment: Alignment.bottomCenter,
169-
child: Padding(
170-
padding: const EdgeInsets.only(bottom: 30),
171-
child: ElevatedButton.icon(
172-
onPressed: () {
173-
rows.add(kNameValueEmptyModel);
174-
isRowEnabledList.add(true);
175-
_onFieldChange(selectedId!);
176-
},
177-
icon: const Icon(Icons.add),
178-
label: const Text(
179-
"Add Param",
180-
style: kTextStyleButton,
181-
),
156+
return Container(
157+
decoration: BoxDecoration(
158+
color: Theme.of(context).colorScheme.background,
159+
borderRadius: kBorderRadius12,
160+
),
161+
margin: kP10,
162+
child: Column(
163+
children: [
164+
Expanded(
165+
child: DaviTheme(
166+
data: kTableThemeData,
167+
child: Davi<NameValueModel>(model),
182168
),
183169
),
184-
),
185-
],
170+
],
171+
),
186172
);
187173
}
188174
}

0 commit comments

Comments
 (0)