Update request_body.dart

This commit is contained in:
Ashita Prasad
2024-09-16 17:02:43 +05:30
parent d9ec943d40
commit c6c215ace1

View File

@ -1,4 +1,3 @@
import 'package:apidash/models/models.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:apidash/providers/providers.dart'; import 'package:apidash/providers/providers.dart';
@ -18,19 +17,20 @@ class EditRequestBody extends ConsumerWidget {
final contentType = ref.watch(selectedRequestModelProvider final contentType = ref.watch(selectedRequestModelProvider
.select((value) => value?.httpRequestModel?.bodyContentType)); .select((value) => value?.httpRequestModel?.bodyContentType));
final sm = ScaffoldMessenger.of(context); // TODO: #178 GET->POST Currently switches to POST everytime user edits body even if the user intentionally chooses GET
void changeToPostMethod() { // final sm = ScaffoldMessenger.of(context);
if (requestModel?.httpRequestModel!.method == HTTPVerb.get) { // void changeToPostMethod() {
ref // if (requestModel?.httpRequestModel!.method == HTTPVerb.get) {
.read(collectionStateNotifierProvider.notifier) // ref
.update(selectedId, method: HTTPVerb.post); // .read(collectionStateNotifierProvider.notifier)
sm.hideCurrentSnackBar(); // .update(selectedId, method: HTTPVerb.post);
sm.showSnackBar(getSnackBar( // sm.hideCurrentSnackBar();
"Switched to POST method", // sm.showSnackBar(getSnackBar(
small: false, // "Switched to POST method",
)); // small: false,
} // ));
} // }
// }
return Column( return Column(
children: [ children: [
@ -48,11 +48,12 @@ class EditRequestBody extends ConsumerWidget {
), ),
Expanded( Expanded(
child: switch (contentType) { child: switch (contentType) {
ContentType.formdata => Padding( ContentType.formdata => const Padding(
padding: kPh4, padding: kPh4,
child: FormDataWidget( child: FormDataWidget(
changeMethodToPost: changeToPostMethod, // TODO: See changeToPostMethod above
)), // changeMethodToPost: changeToPostMethod,
)),
// TODO: Fix JsonTextFieldEditor & plug it here // TODO: Fix JsonTextFieldEditor & plug it here
ContentType.json => Padding( ContentType.json => Padding(
padding: kPt5o10, padding: kPt5o10,
@ -61,7 +62,7 @@ class EditRequestBody extends ConsumerWidget {
fieldKey: "$selectedId-json-body-editor", fieldKey: "$selectedId-json-body-editor",
initialValue: requestModel?.httpRequestModel?.body, initialValue: requestModel?.httpRequestModel?.body,
onChanged: (String value) { onChanged: (String value) {
changeToPostMethod(); // changeToPostMethod();
ref ref
.read(collectionStateNotifierProvider.notifier) .read(collectionStateNotifierProvider.notifier)
.update(selectedId, body: value); .update(selectedId, body: value);
@ -75,7 +76,7 @@ class EditRequestBody extends ConsumerWidget {
fieldKey: "$selectedId-body-editor", fieldKey: "$selectedId-body-editor",
initialValue: requestModel?.httpRequestModel?.body, initialValue: requestModel?.httpRequestModel?.body,
onChanged: (String value) { onChanged: (String value) {
changeToPostMethod(); // changeToPostMethod();
ref ref
.read(collectionStateNotifierProvider.notifier) .read(collectionStateNotifierProvider.notifier)
.update(selectedId, body: value); .update(selectedId, body: value);