1
1
import 'dart:async' ;
2
2
3
3
import 'package:flutter/material.dart' ;
4
- import 'package:flutter_code_editor/flutter_code_editor.dart' ;
5
4
import 'package:flutter_svg/svg.dart' ;
6
- import 'package:highlight/languages/json.dart' as jsonCode;
7
5
import 'package:star_menu/star_menu.dart' ;
8
6
9
7
import '../flow_chart/dashboard.dart' ;
10
8
import '../flow_chart/elements/flow_element.dart' ;
11
9
import '../flow_chart/flow_chart.dart' ;
12
- import 'code_editor_theme .dart' ;
10
+ import '../widgets/json_editor .dart' ;
13
11
14
12
class CustomFlowChart extends StatefulWidget {
15
13
static String name = 'CustomFlowChart' ;
@@ -24,9 +22,13 @@ class _CustomFlowChartState extends State<CustomFlowChart> {
24
22
final segmentedTension = ValueNotifier <double >(1 );
25
23
late final Dashboard dashboard;
26
24
late bool allElementsDraggable;
25
+ String jsonData = "{}" ;
27
26
int selectedIndex = 0 ;
28
27
Offset currentPosition = Offset (0 , 0 );
29
28
Timer ? _debounceTimer;
29
+ final GlobalKey <JsonEditorState > _jsonEditorKey =
30
+ GlobalKey <JsonEditorState >();
31
+
30
32
_CustomFlowChartState () {
31
33
dashboard = Dashboard ();
32
34
allElementsDraggable = dashboard.allElementsDraggable;
@@ -37,14 +39,20 @@ class _CustomFlowChartState extends State<CustomFlowChart> {
37
39
super .initState ();
38
40
Timer (Duration (seconds: 0 ), () {
39
41
_initStartElements ();
42
+ setState (() {
43
+ jsonData = dashboard.toJson ();
44
+ });
40
45
});
41
46
dashboard.addListener (_onDashboardJsonChanged);
42
47
}
43
48
44
49
void _onDashboardJsonChanged () {
45
50
if (_debounceTimer? .isActive ?? false ) _debounceTimer! .cancel ();
46
51
_debounceTimer = Timer (const Duration (milliseconds: 300 ), () {
47
- setState (() {});
52
+ setState (() {
53
+ jsonData = dashboard.toJson ();
54
+ _jsonEditorKey.currentState? .updateJson (jsonData);
55
+ });
48
56
});
49
57
}
50
58
@@ -122,33 +130,26 @@ class _CustomFlowChartState extends State<CustomFlowChart> {
122
130
child: Row (
123
131
children: [
124
132
Container (
125
- width: double .infinity,
126
- height: double .infinity,
127
- constraints: BoxConstraints (
128
- minWidth: 450 ,
129
- maxWidth: 480 ,
130
- ),
131
- decoration: BoxDecoration (
132
- color: Color (0xffffffff ),
133
- ),
134
- child: LayoutBuilder (
135
- builder: (context, constraints) {
136
- return CodeTheme (
137
- data: CodeThemeData (styles: editorDefaultTheme),
138
- child: SingleChildScrollView (
139
- child: CodeField (
140
- enabled: false ,
141
- wrap: true ,
142
- controller: CodeController (
143
- text: dashboard.toPrettyJsonString,
144
- language: jsonCode.json,
145
- ),
146
- minLines: 1 ,
147
- )),
148
- );
149
- },
150
- ),
151
- ),
133
+ width: 480 ,
134
+ height: double .infinity,
135
+ decoration: BoxDecoration (
136
+ color: Color (0xffffffff ),
137
+ ),
138
+ child: Container (
139
+ width: 480 ,
140
+ color: Colors .white,
141
+ child: JsonEditor (
142
+ key: _jsonEditorKey,
143
+ onChanged: (value) {
144
+ // Do something
145
+ },
146
+ hideEditorsMenuButton: true ,
147
+ enableMoreOptions: false ,
148
+ enableValueEdit: false ,
149
+ enableKeyEdit: false ,
150
+ json: jsonData,
151
+ ),
152
+ )),
152
153
Expanded (
153
154
child: Stack (
154
155
children: [
0 commit comments