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

@ -1,3 +1,8 @@
## 1.2.1
- Add argument `doInitFormatting` which if true, formats the json during initialization
- Add argument `fieldKey` to provide the key value of ExtendedTextField widget
## 1.2.0
- Initial release.

View File

@ -90,3 +90,12 @@ Column(
```
Explore the complete example in the `example` folder.
## Maintainer
- Ashita Prasad ([GitHub](https://github.com/ashitaprasad), [LinkedIn](https://www.linkedin.com/in/ashitaprasad/), [X](https://x.com/ashitaprasad))
## License
This project is licensed under the [Apache 2.0 & MIT License](https://github.com/foss42/apidash/blob/main/packages/json_field_editor/LICENSE).

View File

@ -97,7 +97,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.2.0"
version: "1.2.1"
leak_tracker:
dependency: transitive
description:

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,

View File

@ -1,10 +1,10 @@
name: json_field_editor
description: "JSON field editor allows easy editing of JSON text. Unlock the full capabilities of JSON syntax highlighting, validation & formatting."
version: 1.2.0
repository: https://github.com/foss42/apidash/tree/main/packages/json_textfield
homepage: https://github.com/foss42/apidash/tree/main/packages/json_textfield
version: 1.2.1
repository: https://github.com/foss42/apidash/tree/main/packages/json_field_editor
homepage: https://github.com/foss42/apidash/tree/main/packages/json_field_editor
issue_tracker: https://github.com/foss42/apidash/issues
documentation: https://github.com/foss42/apidash/tree/main/packages/json_textfield
documentation: https://github.com/foss42/apidash/tree/main/packages/json_field_editor
environment:
sdk: ^3.7.0

View File

@ -21,6 +21,7 @@ void main() {
child: JsonField(
key: ValueKey("1"),
isFormatting: true,
doInitFormatting: true,
controller: controller,
),
),