Update editor_json.dart

This commit is contained in:
Ankit Mahato
2025-04-09 03:54:52 +05:30
parent 79185f2995
commit ccdba6f482

View File

@ -2,7 +2,7 @@ import 'dart:math' as math;
import 'package:apidash_design_system/apidash_design_system.dart'; import 'package:apidash_design_system/apidash_design_system.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:json_text_field/json_text_field.dart'; import 'package:json_field_editor/json_field_editor.dart';
import 'package:apidash/consts.dart'; import 'package:apidash/consts.dart';
class JsonTextFieldEditor extends StatefulWidget { class JsonTextFieldEditor extends StatefulWidget {
@ -51,10 +51,12 @@ class _JsonTextFieldEditorState extends State<JsonTextFieldEditor> {
if (widget.initialValue != null) { if (widget.initialValue != null) {
controller.text = widget.initialValue!; controller.text = widget.initialValue!;
} }
Future.delayed(Duration(milliseconds: 50), () { // Below code fixes issue #782 but JSON formatting
controller.formatJson(sortJson: false); // should be manual via beautify button
setState(() {}); // Future.delayed(Duration(milliseconds: 50), () {
}); // controller.formatJson(sortJson: false);
// setState(() {});
// });
editorFocusNode = FocusNode(debugLabel: "Editor Focus Node"); editorFocusNode = FocusNode(debugLabel: "Editor Focus Node");
} }
@ -90,7 +92,7 @@ class _JsonTextFieldEditorState extends State<JsonTextFieldEditor> {
insertTab(); insertTab();
}, },
}, },
child: JsonTextField( child: JsonField(
key: Key(widget.fieldKey), key: Key(widget.fieldKey),
commonTextStyle: kCodeStyle.copyWith( commonTextStyle: kCodeStyle.copyWith(
color: Theme.of(context).brightness == Brightness.dark color: Theme.of(context).brightness == Brightness.dark