Skip to content

Commit bd58d0c

Browse files
feat:update json render
1 parent 964f761 commit bd58d0c

File tree

11 files changed

+1347
-181
lines changed

11 files changed

+1347
-181
lines changed

lib/flow_chart/elements/flow_element.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,16 @@ class FlowElement extends ChangeNotifier {
169169
(x) => Handler.values[x as int],
170170
),
171171
),
172-
rowsElementIds: map['rowsElementIds'] as List<List<String>>,
173-
colsElementIds: map['colsElementIds'] as List<List<String>>,
172+
rowsElementIds: (map['rowsElementIds'] as List<dynamic>?)
173+
?.map((row) =>
174+
(row as List<dynamic>).map((id) => id.toString()).toList())
175+
.toList() ??
176+
[],
177+
colsElementIds: (map['colsElementIds'] as List<dynamic>?)
178+
?.map((col) =>
179+
(col as List<dynamic>).map((id) => id.toString()).toList())
180+
.toList() ??
181+
[],
174182
handlerSize: map['handlerSize'].toDouble(),
175183
backgroundColor: Color(map['backgroundColor'] as int),
176184
borderRadius: map['borderRadius'].toDouble(),

lib/pages/custom_flow_chart.dart

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import 'dart:async';
22

33
import 'package:flutter/material.dart';
4-
import 'package:flutter_code_editor/flutter_code_editor.dart';
54
import 'package:flutter_svg/svg.dart';
6-
import 'package:highlight/languages/json.dart' as jsonCode;
75
import 'package:star_menu/star_menu.dart';
86

97
import '../flow_chart/dashboard.dart';
108
import '../flow_chart/elements/flow_element.dart';
119
import '../flow_chart/flow_chart.dart';
12-
import 'code_editor_theme.dart';
10+
import '../widgets/json_editor.dart';
1311

1412
class CustomFlowChart extends StatefulWidget {
1513
static String name = 'CustomFlowChart';
@@ -24,9 +22,13 @@ class _CustomFlowChartState extends State<CustomFlowChart> {
2422
final segmentedTension = ValueNotifier<double>(1);
2523
late final Dashboard dashboard;
2624
late bool allElementsDraggable;
25+
String jsonData = "{}";
2726
int selectedIndex = 0;
2827
Offset currentPosition = Offset(0, 0);
2928
Timer? _debounceTimer;
29+
final GlobalKey<JsonEditorState> _jsonEditorKey =
30+
GlobalKey<JsonEditorState>();
31+
3032
_CustomFlowChartState() {
3133
dashboard = Dashboard();
3234
allElementsDraggable = dashboard.allElementsDraggable;
@@ -37,14 +39,20 @@ class _CustomFlowChartState extends State<CustomFlowChart> {
3739
super.initState();
3840
Timer(Duration(seconds: 0), () {
3941
_initStartElements();
42+
setState(() {
43+
jsonData = dashboard.toJson();
44+
});
4045
});
4146
dashboard.addListener(_onDashboardJsonChanged);
4247
}
4348

4449
void _onDashboardJsonChanged() {
4550
if (_debounceTimer?.isActive ?? false) _debounceTimer!.cancel();
4651
_debounceTimer = Timer(const Duration(milliseconds: 300), () {
47-
setState(() {});
52+
setState(() {
53+
jsonData = dashboard.toJson();
54+
_jsonEditorKey.currentState?.updateJson(jsonData);
55+
});
4856
});
4957
}
5058

@@ -122,33 +130,26 @@ class _CustomFlowChartState extends State<CustomFlowChart> {
122130
child: Row(
123131
children: [
124132
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+
)),
152153
Expanded(
153154
child: Stack(
154155
children: [

0 commit comments

Comments
 (0)