Update widget to write Query

This commit is contained in:
Ashita Prasad
2025-01-12 15:48:35 +05:30
parent ca31d11388
commit 2ebeded784

View File

@ -18,6 +18,8 @@ class EditRequestBody extends ConsumerWidget {
.getRequestModel(selectedId!); .getRequestModel(selectedId!);
final contentType = ref.watch(selectedRequestModelProvider final contentType = ref.watch(selectedRequestModelProvider
.select((value) => value?.httpRequestModel?.bodyContentType)); .select((value) => value?.httpRequestModel?.bodyContentType));
final apiType = ref
.watch(selectedRequestModelProvider.select((value) => value?.apiType));
// TODO: #178 GET->POST Currently switches to POST everytime user edits body even if the user intentionally chooses GET // TODO: #178 GET->POST Currently switches to POST everytime user edits body even if the user intentionally chooses GET
// final sm = ScaffoldMessenger.of(context); // final sm = ScaffoldMessenger.of(context);
@ -36,7 +38,8 @@ class EditRequestBody extends ConsumerWidget {
return Column( return Column(
children: [ children: [
const SizedBox( (apiType == APIType.rest)
? const SizedBox(
height: kHeaderHeight, height: kHeaderHeight,
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
@ -47,8 +50,10 @@ class EditRequestBody extends ConsumerWidget {
DropdownButtonBodyContentType(), DropdownButtonBodyContentType(),
], ],
), ),
), )
Expanded( : kSizedBoxEmpty,
switch (apiType) {
APIType.rest => Expanded(
child: switch (contentType) { child: switch (contentType) {
ContentType.formdata => const Padding( ContentType.formdata => const Padding(
padding: kPh4, padding: kPh4,
@ -67,8 +72,9 @@ class EditRequestBody extends ConsumerWidget {
// changeToPostMethod(); // changeToPostMethod();
ref ref
.read(collectionStateNotifierProvider.notifier) .read(collectionStateNotifierProvider.notifier)
.update(selectedId, body: value); .update(body: value);
}, },
hintText: "Enter JSON",
), ),
), ),
_ => Padding( _ => Padding(
@ -81,12 +87,31 @@ class EditRequestBody extends ConsumerWidget {
// changeToPostMethod(); // changeToPostMethod();
ref ref
.read(collectionStateNotifierProvider.notifier) .read(collectionStateNotifierProvider.notifier)
.update(selectedId, body: value); .update(body: value);
}, },
hintText: "Enter text",
), ),
), ),
}, },
) ),
APIType.graphql => Expanded(
child: Padding(
padding: kPt5o10,
child: TextFieldEditor(
key: Key("$selectedId-query"),
fieldKey: "$selectedId-query-editor",
initialValue: requestModel?.httpRequestModel?.query,
onChanged: (String value) {
ref
.read(collectionStateNotifierProvider.notifier)
.update(query: value);
},
hintText: "Enter Query",
),
),
),
_ => kSizedBoxEmpty,
}
], ],
); );
} }
@ -99,7 +124,7 @@ class DropdownButtonBodyContentType extends ConsumerWidget {
@override @override
Widget build(BuildContext context, WidgetRef ref) { Widget build(BuildContext context, WidgetRef ref) {
final selectedId = ref.watch(selectedIdStateProvider); ref.watch(selectedIdStateProvider);
final requestBodyContentType = ref.watch(selectedRequestModelProvider final requestBodyContentType = ref.watch(selectedRequestModelProvider
.select((value) => value?.httpRequestModel?.bodyContentType)); .select((value) => value?.httpRequestModel?.bodyContentType));
return DropdownButtonContentType( return DropdownButtonContentType(
@ -107,7 +132,7 @@ class DropdownButtonBodyContentType extends ConsumerWidget {
onChanged: (ContentType? value) { onChanged: (ContentType? value) {
ref ref
.read(collectionStateNotifierProvider.notifier) .read(collectionStateNotifierProvider.notifier)
.update(selectedId!, bodyContentType: value); .update(bodyContentType: value);
}, },
); );
} }