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,57 +38,80 @@ class EditRequestBody extends ConsumerWidget {
return Column( return Column(
children: [ children: [
const SizedBox( (apiType == APIType.rest)
height: kHeaderHeight, ? const SizedBox(
child: Row( height: kHeaderHeight,
mainAxisAlignment: MainAxisAlignment.center, child: Row(
children: [ mainAxisAlignment: MainAxisAlignment.center,
Text( children: [
"Select Content Type:", Text(
), "Select Content Type:",
DropdownButtonBodyContentType(), ),
], DropdownButtonBodyContentType(),
), ],
), ),
Expanded( )
child: switch (contentType) { : kSizedBoxEmpty,
ContentType.formdata => const Padding( switch (apiType) {
padding: kPh4, APIType.rest => Expanded(
child: FormDataWidget( child: switch (contentType) {
// TODO: See changeToPostMethod above ContentType.formdata => const Padding(
// changeMethodToPost: changeToPostMethod, padding: kPh4,
)), child: FormDataWidget(
// TODO: Fix JsonTextFieldEditor & plug it here // TODO: See changeToPostMethod above
ContentType.json => Padding( // changeMethodToPost: changeToPostMethod,
)),
// TODO: Fix JsonTextFieldEditor & plug it here
ContentType.json => Padding(
padding: kPt5o10,
child: TextFieldEditor(
key: Key("$selectedId-json-body"),
fieldKey: "$selectedId-json-body-editor",
initialValue: requestModel?.httpRequestModel?.body,
onChanged: (String value) {
// changeToPostMethod();
ref
.read(collectionStateNotifierProvider.notifier)
.update(body: value);
},
hintText: "Enter JSON",
),
),
_ => Padding(
padding: kPt5o10,
child: TextFieldEditor(
key: Key("$selectedId-body"),
fieldKey: "$selectedId-body-editor",
initialValue: requestModel?.httpRequestModel?.body,
onChanged: (String value) {
// changeToPostMethod();
ref
.read(collectionStateNotifierProvider.notifier)
.update(body: value);
},
hintText: "Enter text",
),
),
},
),
APIType.graphql => Expanded(
child: Padding(
padding: kPt5o10, padding: kPt5o10,
child: TextFieldEditor( child: TextFieldEditor(
key: Key("$selectedId-json-body"), key: Key("$selectedId-query"),
fieldKey: "$selectedId-json-body-editor", fieldKey: "$selectedId-query-editor",
initialValue: requestModel?.httpRequestModel?.body, initialValue: requestModel?.httpRequestModel?.query,
onChanged: (String value) { onChanged: (String value) {
// changeToPostMethod();
ref ref
.read(collectionStateNotifierProvider.notifier) .read(collectionStateNotifierProvider.notifier)
.update(selectedId, body: value); .update(query: value);
}, },
hintText: "Enter Query",
), ),
), ),
_ => Padding( ),
padding: kPt5o10, _ => kSizedBoxEmpty,
child: TextFieldEditor( }
key: Key("$selectedId-body"),
fieldKey: "$selectedId-body-editor",
initialValue: requestModel?.httpRequestModel?.body,
onChanged: (String value) {
// changeToPostMethod();
ref
.read(collectionStateNotifierProvider.notifier)
.update(selectedId, body: value);
},
),
),
},
)
], ],
); );
} }
@ -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);
}, },
); );
} }