Publish json_field_editor 1.2.1

This commit is contained in:
Ankit Mahato
2025-04-12 23:59:15 +05:30
parent 6ad6dc91c4
commit 76150da928
6 changed files with 33 additions and 6 deletions

View File

@@ -11,6 +11,7 @@ class JsonField extends ExtendedTextField {
const JsonField({
super.key,
this.fieldKey,
super.autocorrect,
super.autofillHints,
super.autofocus,
@@ -82,12 +83,19 @@ class JsonField extends ExtendedTextField {
this.errorContainerDecoration,
this.showErrorMessage = false,
this.isFormatting = true,
this.doInitFormatting = false,
this.onError,
});
/// If true, the text will be formatted as json. If false, the text field will behave as a normal text field. Default is true.
final bool isFormatting;
/// If true, the text will be formatted during initialization
final bool doInitFormatting;
/// Provide the key value for ExtendedTextField widget
final String? fieldKey;
/// TextStyle for the json key.
final TextStyle? keyHighlightStyle;
@@ -164,7 +172,9 @@ class JsonFieldState extends State<JsonField> {
@override
void initState() {
controller.text =
(widget.isFormatting && JsonUtils.isValidJson(controller.text))
(widget.doInitFormatting &&
widget.isFormatting &&
JsonUtils.isValidJson(controller.text))
? JsonUtils.getPrettyPrintJson(controller.text)
: controller.text;
@@ -172,12 +182,14 @@ class JsonFieldState extends State<JsonField> {
}
void _setJsonError(String? error) => setState(() => jsonError = error);
@override
Widget build(BuildContext context) {
return Stack(
alignment: AlignmentDirectional.bottomCenter,
children: [
ExtendedTextField(
key: widget.fieldKey != null ? ValueKey(widget.fieldKey!) : null,
autocorrect: widget.autocorrect,
autofillHints: widget.autofillHints,
autofocus: widget.autofocus,