diff --git a/lib/dashbot/widgets/home_screen_task_button.dart b/lib/dashbot/widgets/home_screen_task_button.dart index 881a96b80a..601d1a928b 100644 --- a/lib/dashbot/widgets/home_screen_task_button.dart +++ b/lib/dashbot/widgets/home_screen_task_button.dart @@ -21,13 +21,18 @@ class HomeScreenTaskButton extends StatelessWidget { color: Theme.of(context).colorScheme.primary, ), padding: const EdgeInsets.symmetric( - vertical: 0, + vertical: 8, // increased padding horizontal: 16, ), ), - child: Text( - label, - textAlign: textAlign, + child: Tooltip( // NEW + message: label, + child: Text( + label, + textAlign: textAlign, + overflow: TextOverflow.ellipsis, // NEW + maxLines: 1, // NEW + ), ), ); } diff --git a/lib/screens/home_page/editor_pane/details_card/request_pane/request_body.dart b/lib/screens/home_page/editor_pane/details_card/request_pane/request_body.dart index e6c9826bb6..a7ead9d58d 100644 --- a/lib/screens/home_page/editor_pane/details_card/request_pane/request_body.dart +++ b/lib/screens/home_page/editor_pane/details_card/request_pane/request_body.dart @@ -1,3 +1,5 @@ +import 'dart:convert'; // NEW + import 'package:apidash_core/apidash_core.dart'; import 'package:apidash_design_system/apidash_design_system.dart'; import 'package:flutter/material.dart'; @@ -10,6 +12,16 @@ import 'request_form_data.dart'; class EditRequestBody extends ConsumerWidget { const EditRequestBody({super.key}); + // NEW FUNCTION + bool isValidJson(String input) { + try { + jsonDecode(input); + return true; + } catch (e) { + return false; + } + } + @override Widget build(BuildContext context, WidgetRef ref) { final selectedId = ref.watch(selectedIdStateProvider); @@ -44,58 +56,83 @@ class EditRequestBody extends ConsumerWidget { : kSizedBoxEmpty, switch (apiType) { APIType.rest => Expanded( - child: switch (contentType) { - ContentType.formdata => const Padding( - padding: kPh4, - child: FormDataWidget(), - ), - ContentType.json => Padding( - padding: kPt5o10, - child: JsonTextFieldEditor( - key: Key("$selectedId-json-body"), - fieldKey: "$selectedId-json-body-editor-$darkMode", - isDark: darkMode, - initialValue: requestModel?.httpRequestModel?.body, - onChanged: (String value) { - ref - .read(collectionStateNotifierProvider.notifier) - .update(body: value); - }, - hintText: kHintJson, - ), - ), - _ => Padding( - padding: kPt5o10, - child: TextFieldEditor( - key: Key("$selectedId-body"), - fieldKey: "$selectedId-body-editor", - initialValue: requestModel?.httpRequestModel?.body, - onChanged: (String value) { - ref - .read(collectionStateNotifierProvider.notifier) - .update(body: value); - }, - hintText: kHintText, - ), + child: switch (contentType) { + ContentType.formdata => const Padding( + padding: kPh4, + child: FormDataWidget(), + ), + ContentType.json => Padding( + padding: kPt5o10, + child: JsonTextFieldEditor( + key: Key("$selectedId-json-body"), + fieldKey: "$selectedId-json-body-editor-$darkMode", + isDark: darkMode, + initialValue: + requestModel?.httpRequestModel?.body, + + + onChanged: (String value) { + if (value.isNotEmpty && + !isValidJson(value)) { + ScaffoldMessenger.of(context) + .showSnackBar( + const SnackBar( + content: + Text("Invalid JSON format"), + backgroundColor: Colors.red, + ), + ); + return; + } + + ref + .read( + collectionStateNotifierProvider + .notifier) + .update(body: value); + }, + + hintText: kHintJson, + ), + ), + _ => Padding( + padding: kPt5o10, + child: TextFieldEditor( + key: Key("$selectedId-body"), + fieldKey: "$selectedId-body-editor", + initialValue: + requestModel?.httpRequestModel?.body, + onChanged: (String value) { + ref + .read( + collectionStateNotifierProvider + .notifier) + .update(body: value); + }, + hintText: kHintText, + ), + ), + }, ), - }, - ), 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: kHintQuery, + 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: kHintQuery, + ), + ), ), - ), - ), _ => kSizedBoxEmpty, }, ], diff --git a/lib/widgets/tab_label.dart b/lib/widgets/tab_label.dart index 7001db9174..994fa72164 100644 --- a/lib/widgets/tab_label.dart +++ b/lib/widgets/tab_label.dart @@ -8,6 +8,7 @@ class TabLabel extends StatelessWidget { required this.text, this.showIndicator = false, }); + final String text; final bool showIndicator; @@ -18,12 +19,15 @@ class TabLabel extends StatelessWidget { child: Stack( children: [ Center( - child: Text( - text, - textAlign: TextAlign.center, - overflow: TextOverflow.fade, - softWrap: false, - style: kTextStyleTab, + child: Tooltip( // NEW + message: text, + child: Text( + text, + textAlign: TextAlign.center, + overflow: TextOverflow.ellipsis, // improved + maxLines: 1, // NEW + style: kTextStyleTab, + ), ), ), if (showIndicator)