missing files

This commit is contained in:
mr
2025-02-05 09:07:39 +01:00
parent 05854c84d8
commit bed48b4cb4
31 changed files with 947 additions and 681 deletions

View File

@@ -1 +1 @@
3.19.6
3.24.3

View File

@@ -5,5 +5,5 @@ export 'src/dashboard.dart';
export 'src/elements/connection_params.dart';
export 'src/elements/flow_element.dart';
export 'src/flow_chart.dart';
export 'src/ui/draw_arrow.dart' show ArrowParams, ArrowStyle, ArrowDirection;
export 'src/ui/draw_arrow.dart' show ArrowParams, ArrowStyle, ArrowDirection, ArrowPainter;
export 'src/ui/grid_background.dart' show GridBackgroundParams;

View File

@@ -28,13 +28,11 @@ class Dashboard extends ChangeNotifier {
GlobalKey<FlowChartMenuState> chartMenuKey = GlobalKey<FlowChartMenuState>();
GlobalKey<ChartWidgetState> chartKey = GlobalKey<ChartWidgetState>();
GlobalKey<FlowChartState> flutterChartKey = GlobalKey<FlowChartState>();
bool inDialog = false;
List<Map<String, dynamic>> tempHistory = [];
List<Map<String, dynamic>> history = [];
Map<String, dynamic> scheduler = {};
Map<String, dynamic> info = {};
bool scheduleActive = false;
String? id;
String name = "";
bool isMenu = true;
@@ -47,8 +45,9 @@ class Dashboard extends ChangeNotifier {
double defaultDashWidth = 0;
double defaultBackWidth = 10;
double defaultForwardWidth = 10;
Future<void> Function(String? id)? save;
Future<void> Function(String? id, BuildContext? context)? save;
List<Widget> Function(FlowData? obj, String id)? infoItemWidget;
Widget Function(ArrowPainter item)? infoLinkWidget;
List<Widget> Function()? infoWidget;
FlowData? Function(Map<String, dynamic> json)? transformToData;
bool addChange = false;
@@ -74,7 +73,6 @@ class Dashboard extends ChangeNotifier {
this.save,
this.dashColor = Colors.grey,
this.midDashColor = Colors.blueGrey,
this.scheduler = const {},
Offset? handlerFeedbackOffset,
this.isMenu = true,
this.defaultDashSpace = 0,
@@ -93,7 +91,7 @@ class Dashboard extends ChangeNotifier {
// This is a workaround to set the handlerFeedbackOffset
// to improve the user experience on devices with touch screens
// This will prevent the handler being covered by user's finger
if (loadedGraph != null) { deserialize(loadedGraph!); }
if (loadedGraph != null) { deserialize(loadedGraph!, false); }
if (handlerFeedbackOffset != null) {
this.handlerFeedbackOffset = handlerFeedbackOffset;
} else {
@@ -110,18 +108,15 @@ class Dashboard extends ChangeNotifier {
tempHistory = [];
history = [];
}
Future<void> saveDash(String? id) async {
shouldSave = true;
Future<void> saveDash(String? id, BuildContext? context) async {
for (var element in saveRules) {
if (element(this)) {
shouldSave = true;
} else {
if (!element(this)) {
shouldSave = false;
break;
}
}
if (save != null && shouldSave) {
save!(id);
save!(id, context);
}
}
Future<void> Function(String cat)? load;
@@ -131,14 +126,12 @@ class Dashboard extends ChangeNotifier {
final d = Dashboard(
name: map['name'] as String,
isMenu: map['isMenu'] as bool,
scheduler: map['schedule'] as Map<String, String>? ?? {},
defaultDashSpace: map['defaultDashSpace'] as double? ?? 0,
defaultDashWidth: map['defaultDashWidth'] as double? ?? 0,
defaultArrowDirection: ArrowDirection.values[
map['defaultArrowDirection'] as int? ?? 0],
defaultArrowStyle: ArrowStyle.values[map['arrowStyle'] as int? ?? 0],
);
d..scheduleActive = map['schedule_active'] as bool? ?? false;
d..arrows = List<ArrowPainter>.from(
(map['arrows'] as List<dynamic>).map<ArrowPainter>(
(x) => ArrowPainter.fromMap(x as Map<String, dynamic>),
@@ -170,15 +163,14 @@ class Dashboard extends ChangeNotifier {
}
void copyFromMap(Map<String, dynamic> map) {
scheduleActive = map['schedule_active'] as bool? ?? false;
scheduler = map['schedule'] as Map<String, String>? ?? {};
debugPrintStack(stackTrace: StackTrace.current, label: 'my_label', maxFrames: 5);
defaultArrowStyle = ArrowStyle.values[map['arrowStyle'] as int? ?? 0];
defaultDashSpace = map['defaultDashSpace'] as double? ?? 0;
defaultDashWidth = map['defaultDashWidth'] as double? ?? 0;
defaultArrowDirection = ArrowDirection.values[
map['defaultArrowDirection'] as int? ?? 0];
arrows = List<ArrowPainter>.from(
(map['arrows'] as List<dynamic>).map<ArrowPainter>(
(map['arrows'] as List<dynamic>).map<ArrowPainter>(
(x) => ArrowPainter.fromMap(x as Map<String, dynamic>),
),
);
@@ -257,26 +249,25 @@ class Dashboard extends ChangeNotifier {
d["id"]=id;
d["name"]=name;
d["graph"]=graph;
d["schedule"]=scheduler;
d["schedule_active"]=scheduleActive;
return d;
}
void deserialize(Map<String, dynamic> graph) {
void deserialize(Map<String, dynamic> graph, bool noHistory) {
elements = [];
arrows = [];
info["shared"] = graph["shared"] ?? [];
scheduler = graph['schedule'] ?? {};
scheduleActive = graph['schedule_active'] ?? false;
setZoomFactor(graph["graph"]?["zoom"] ?? 1.0);
for(var el in graph['graph']?['elements'] ?? []) {
List<ConnectionParams> nexts = [];
var flow = FlowElement.deserialize(this, el);
for(var ar in graph['graph']['arrows']) {
if (ar['from']['id'] != flow.id) { continue; }
nexts.add(ConnectionParams(
srcElementId: ar['from']['id'],
destElementId: ar['to']['id'],
infos: ar['infos'],
env: ar['env'],
arrowParams: ArrowParams.fromMap(ar["params"]),
pivots: [
Pivot(Offset(ar['from']['x'], (ar['from']['y']))),
@@ -291,16 +282,35 @@ class Dashboard extends ChangeNotifier {
arr.add(build);
}
}
try {
FlowData data = arr.firstWhere((element) => element.getID() == flow.element?.getID());
if (flow.element != null) {
flow.kind = ElementKind.widget;
flow.widget = chartKey.currentState?.widget.flowChart.widget.itemWidget(data);
} catch (e) { print(e); }
flow.widget = chartKey.currentState?.widget.flowChart.widget.itemWidget(flow.element!);
}
elements.add(flow);
}
selectedMenuKey.currentState?.setState(() { });
chartMenuKey.currentState?.setState(() { });
addToHistory();
if (!noHistory) {
addToHistory();
}
}
void applyInfos(Map<String, List<dynamic>> elInfos, Map<String, dynamic> graph) {
for(var id in elInfos.keys) {
try {
var element = elements.firstWhere((element) => element.id == id);
element.element?.addEnv(elInfos[id] ?? []);
} catch (e) { print("THERE ??? ${id} ${e}"); }
}
for(var ar in graph['graph']['arrows']) {
var arr = arrows.where((a) => a.fromID == ar['from']['id'] && a.toID == ar['to']['id']).toList();
for (var a in arr) {
a.infos = ar['infos'];
a.env = ar['env'];
}
}
selectedLeftMenuKey.currentState?.setState(() { });
}
/// add listener called when a new connection is created
@@ -325,30 +335,31 @@ class Dashboard extends ChangeNotifier {
handlerFeedbackOffset = offset;
}
List<ArrowPainter> GetArrowByElementID(String id, bool isinput) {
return arrows.where((element) => (isinput && element.toID.contains(id)) || (!isinput && element.fromID.contains(id))).toList();
List<ArrowPainter> getArrowByElementID(String id, bool isinput) {
return arrows.where((element) =>
(isinput && element.toID.contains(id)) || (!isinput && element.fromID.contains(id))).toList();
}
void addArrows(ArrowPainter f) {
void addArrows(ArrowPainter f, BuildContext? context) {
arrows.add(f);
for (var f in arrowStyleRules) {
arrows = f(this);
}
addChange = true;
saveDash(id);
saveDash(id, context);
}
void removeArrows(bool Function(ArrowPainter) f) {
void removeArrows(bool Function(ArrowPainter) f, BuildContext? context) {
arrows.removeWhere((element) => f(element));
for (var f in arrowStyleRules) {
arrows = f(this);
}
saveDash(id);
saveDash(id, context);
}
void removeElements(bool Function(FlowElement<FlowData>) f) {
void removeElements(bool Function(FlowElement<FlowData>) f, BuildContext? context) {
elements.removeWhere((element) => f(element));
saveDash(id);
saveDash(id, context);
}
void clear() {
@@ -356,9 +367,7 @@ class Dashboard extends ChangeNotifier {
arrows.clear();
tempHistory = [];
history = [];
scheduler = {};
info = {};
scheduleActive = false;
notifyListeners();
}
bool noHistory = false;
@@ -375,14 +384,13 @@ class Dashboard extends ChangeNotifier {
Future.delayed(Duration(seconds: 1), () {
chartMenuKey.currentState?.setState(() { });
});
;
}
bool isBack = false;
void back() {
if (canBack()) {
noHistory = true;
tempHistory.removeLast();
if (tempHistory.length > 0) {
if (tempHistory.isNotEmpty) {
copyFromMap(tempHistory.last);
}
chartKey.currentState?.setState(() { });
@@ -413,28 +421,29 @@ class Dashboard extends ChangeNotifier {
FlowElement element,
bool resizable, {
bool notify = true,
BuildContext? context
}) {
element.isResizing = resizable;
saveDash(id);
saveDash(id, context);
if (notify) notifyListeners();
}
FlowElement? getElement(String id, {bool notify = true}) {
try { return elements.firstWhere((element) {
return element.id == id;
return id.contains(element.id);
}); }
catch (e) { return null; }
}
/// add a [FlowElement] to the dashboard
void addElement(FlowElement element, {bool notify = true}) {
void addElement(FlowElement element, BuildContext? context, {bool notify = true}) {
if (element.id.isEmpty) {
element.id = const Uuid().v4();
}
element.setScale(1, gridBackgroundParams.scale);
elements.add(element);
addChange = true;
saveDash(id);
saveDash(id, context);
if (notify) {
notifyListeners();
}
@@ -554,16 +563,16 @@ class Dashboard extends ChangeNotifier {
}
/// remove all elements
void removeAllElements({bool notify = true}) {
void removeAllElements(BuildContext? context, {bool notify = true}) {
elements.clear();
if (notify) notifyListeners();
saveDash(id);
saveDash(id, context);
}
/// remove the [handler] connection of [element]
void removeElementConnection(
FlowElement element,
Handler handler, {
Handler handler, BuildContext? context, {
bool notify = true,
}) {
Alignment alignment;
@@ -600,7 +609,7 @@ class Dashboard extends ChangeNotifier {
}
}
if (notify) notifyListeners();
saveDash(id);
saveDash(id, context);
}
/// dissect an element connection
@@ -690,14 +699,14 @@ class Dashboard extends ChangeNotifier {
}
/// remove all the connection from the [element]
void removeElementConnections(FlowElement element, {bool notify = true}) {
void removeElementConnections(FlowElement element, BuildContext? context, {bool notify = true}) {
element.next.clear();
if (notify) notifyListeners();
saveDash(id);
saveDash(id, context);
}
/// remove all the elements with [id] from the dashboard
void removeElementById(String id, {bool notify = true}) {
void removeElementById(String id, BuildContext? context, {bool notify = true}) {
// remove the element
var elementId = '';
elements.removeWhere((element) {
@@ -714,12 +723,12 @@ class Dashboard extends ChangeNotifier {
});
}
if (notify) notifyListeners();
saveDash(id);
saveDash(id, context);
}
/// remove element
/// return true if it has been removed
bool removeElement(FlowElement element, {bool notify = true}) {
bool removeElement(FlowElement element, BuildContext? context, {bool notify = true}) {
// remove the element
var found = false;
final elementId = element.id;
@@ -735,7 +744,7 @@ class Dashboard extends ChangeNotifier {
);
}
if (notify) notifyListeners();
saveDash(id);
saveDash(id, context);
return found;
}

View File

@@ -11,14 +11,19 @@ class ConnectionParams {
required this.srcElementId,
required this.destElementId,
required this.arrowParams,
this.env = const [],
this.infos = const [],
List<Pivot>? pivots,
}) : pivots = pivots ?? [];
List<dynamic> env = [];
List<dynamic> infos = [];
///
factory ConnectionParams.fromMap(Map<String, dynamic> map) {
return ConnectionParams(
srcElementId: map['srcElementId'] as String,
destElementId: map['destElementId'] as String,
infos: map['infos'] as List<dynamic>? ?? [],
env: map['env'] as List<dynamic>? ?? [],
arrowParams: ArrowParams.fromMap(map['arrowParams'] as Map<String, dynamic>),
pivots: (map['pivots'] as List?)
?.map<Pivot>(
@@ -37,7 +42,6 @@ class ConnectionParams {
final String destElementId;
final String srcElementId;
/// Arrow parameters.
final ArrowParams arrowParams;

View File

@@ -374,6 +374,7 @@ class FlowElement<T extends FlowData> extends ChangeNotifier {
graphElement['width'] = size.width;
graphElement['height'] = size.height;
graphElement['element']=element?.serialize();
graphElement['next'] = next.map((x) => x.toMap()).toList();
return graphElement;
}
@@ -385,6 +386,13 @@ class FlowElement<T extends FlowData> extends ChangeNotifier {
position: Offset(double.parse("${map['x']}"), double.parse("${map['y']}")),
size: Size(double.parse("${map['width']}"), double.parse("${map['height']}")),
element: (dashboard.transformToData != null ? dashboard.transformToData!(map['element'] ?? {}) : null) as T?,
/*next: map['next'] != null && (map['next'] as List).isNotEmpty
? List<ConnectionParams>.from(
(map['next'] as List<dynamic>).map<dynamic>(
(x) => ConnectionParams.fromMap(x as Map<String, dynamic>),
),
)
: []*/
);
}
}

View File

@@ -1,29 +1,27 @@
// ignore: directives_ordering
import 'dart:developer';
import 'package:uuid/uuid.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_flow_chart/flutter_flow_chart.dart';
import 'package:flutter_flow_chart/src/flow_chart_left_menu.dart';
import 'package:flutter_flow_chart/src/flow_chart_menu.dart';
import 'package:flutter_flow_chart/src/flow_chart_selected_menu.dart';
import 'package:flutter_flow_chart/src/ui/draw_arrow.dart';
import 'package:flutter_flow_chart/flutter_flow_chart.dart';
import 'package:flutter_flow_chart/src/flow_chart_menu.dart';
import 'package:flutter_flow_chart/src/ui/element_widget.dart';
import 'package:flutter_flow_chart/src/ui/grid_background.dart';
import 'package:flutter_flow_chart/src/ui/segment_handler.dart';
import 'package:uuid/uuid.dart';
import 'package:flutter_flow_chart/src/flow_chart_left_menu.dart';
import 'package:flutter_flow_chart/src/flow_chart_selected_menu.dart';
/// Main flow chart Widget.
/// It displays the background grid, all the elements and connection lines
abstract class FlowData {
String getID();
String getName();
String getType();
double? getWidth();
double? getHeight();
Map<String, dynamic> setVariable(List<String> keys, dynamic value, Map<String, dynamic> map);
dynamic getVariable(List<String> keys, Map<String, dynamic> map);
void addEnv(List<dynamic> infos);
Map<String, dynamic> serialize();
FlowData deserialize(Map<String, dynamic> data);
}
@@ -321,17 +319,21 @@ class FlowChartState<T extends FlowData> extends State<FlowChart> {
Future.delayed(Duration(milliseconds: 100), () => widget.dashboard.load!(widget.dashboard.id!) );
} else {
Future.delayed(Duration(milliseconds: 100), () {
showDialog(
barrierDismissible: false,
context: context, builder: (context) {
return AlertDialog(
titlePadding: EdgeInsets.zero,
insetPadding: EdgeInsets.zero,
backgroundColor: Colors.white,
shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(0)),
title: widget.onDashboardAlertOpened!(context, widget.dashboard));
}); });
if (!widget.dashboard.inDialog) {
widget.dashboard.inDialog = true;
showDialog(
barrierDismissible: false,
context: context, builder: (context) {
return AlertDialog(
titlePadding: EdgeInsets.zero,
insetPadding: EdgeInsets.zero,
backgroundColor: Colors.white,
shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(0)),
title: widget.onDashboardAlertOpened!(context, widget.dashboard));
});
}
});
}
} else {
widget.dashboard.isOpened = true;
@@ -357,14 +359,14 @@ class FlowChartState<T extends FlowData> extends State<FlowChart> {
onKeyEvent: (event) {
bool change = false;
if (event.logicalKey == LogicalKeyboardKey.controlLeft) {
isCtrl = event is KeyDownEvent || event is KeyRepeatEvent;
isCtrl = event is KeyDownEvent || event is KeyRepeatEvent;
}
if (event is KeyDownEvent || event.logicalKey == LogicalKeyboardKey.keyZ && isCtrl) {
/*if ((event is KeyDownEvent || event.logicalKey == LogicalKeyboardKey.keyZ) && isCtrl) {
widget.dashboard.back();
}
if (event is KeyDownEvent || event.logicalKey == LogicalKeyboardKey.keyY && isCtrl) {
if ((event is KeyDownEvent || event.logicalKey == LogicalKeyboardKey.keyY) && isCtrl) {
widget.dashboard.forward();
}
}*/
if (event is KeyDownEvent && event.logicalKey == LogicalKeyboardKey.add) {
change = true;
for (var el in widget.dashboard.elementSelected) {
@@ -379,18 +381,18 @@ class FlowChartState<T extends FlowData> extends State<FlowChart> {
kind: el.kind,
handlers: el.handlers,
handlerSize: el.handlerSize,
));
), context);
}
}
if (event is KeyDownEvent && event.logicalKey == LogicalKeyboardKey.delete) {
change = true;
widget.dashboard.removeElements( (el) => el.isSelected );
widget.dashboard.removeElements( (el) => el.isSelected, context );
for (var arrow in widget.dashboard.arrowsSelected) {
for (var el in widget.dashboard.elements.where((element) => element.id == arrow.fromID.split("_")[0])) {
el.next.removeAt(int.parse(arrow.fromID.split("_")[1]));
}
}
widget.dashboard.removeArrows( (el) => el.isSelected );
widget.dashboard.removeArrows( (el) => el.isSelected, context );
}
if (change) {
DrawingArrow.instance.notifyListeners();
@@ -459,7 +461,7 @@ class FlowChartState<T extends FlowData> extends State<FlowChart> {
Handler.rightCenter,
],
);
widget.dashboard.addElement(el);
widget.dashboard.addElement(el, context);
},
))]
),
@@ -495,8 +497,8 @@ class FlowChartState<T extends FlowData> extends State<FlowChart> {
onDragEnd: (d) => node.requestFocus(),
childWhenDragging: Opacity(opacity: .5,
child: Padding( padding: const EdgeInsets.all(10),
child: Container( child: widget.itemWidget(e), alignment: Alignment.center,
constraints: BoxConstraints(maxHeight: realSize - 10, maxWidth: realSize - 10), ))),
child: Container( alignment: Alignment.center,
constraints: BoxConstraints(maxHeight: realSize - 10, maxWidth: realSize - 10), child: widget.itemWidget(e), ))),
feedback: Container( alignment: Alignment.center, constraints: BoxConstraints(maxHeight: realSize, maxWidth: realSize),
child: widget.itemWidget(e) ),
child: InkWell( mouseCursor: SystemMouseCursors.grab, child: Padding( padding: const EdgeInsets.all(10),
@@ -548,6 +550,8 @@ class _DrawingArrowWidgetState extends State<DrawingArrowWidget> {
painter: ArrowPainter(
fromID: DrawingArrow.instance.fromID,
toID: "",
env: DrawingArrow.instance.env,
infos: DrawingArrow.instance.infos,
params: DrawingArrow.instance.params,
from: DrawingArrow.instance.from,
to: DrawingArrow.instance.to,
@@ -878,9 +882,7 @@ class ChartWidgetState<T extends FlowData> extends State<ChartWidget> {
),
// Draw arrows
for (int i = 0; i < widget.dashboard.elements.length; i++)
for (int n = 0; n < widget.dashboard.elements[i].next.length; n++)
DrawArrow(
flow: this,
key: UniqueKey(),
@@ -889,6 +891,8 @@ class ChartWidgetState<T extends FlowData> extends State<ChartWidget> {
destElement: widget.dashboard.elements[widget.dashboard.findElementIndexById(
widget.dashboard.elements[i].next[n].destElementId,
)],
env: widget.dashboard.elements[i].next[n].env,
infos: widget.dashboard.elements[i].next[n].infos,
arrowParams: widget.dashboard.elements[i].next[n].arrowParams,
pivots: widget.dashboard.elements[i].next[n].pivots,
),

View File

@@ -37,17 +37,20 @@ class FlowChartMenuState extends State<FlowChartMenu> {
onTap: () {
widget.dashboard.name = "graph_${DateTime.now().toString().replaceAll(" ", "_").substring(0, DateTime.now().toString().length - 7)}";
widget.dashboard.isOpened = true;
showDialog(
barrierDismissible: false,
context: context, builder: (context) {
return AlertDialog(
titlePadding: EdgeInsets.zero,
insetPadding: EdgeInsets.zero,
backgroundColor: Colors.white,
shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(0)),
title: widget.chart.widget.flowChart.widget.onDashboardAlertOpened!(
context, widget.dashboard));
});
if (!widget.dashboard.inDialog) {
widget.dashboard.inDialog = true;
showDialog(
barrierDismissible: false,
context: context, builder: (context) {
return AlertDialog(
titlePadding: EdgeInsets.zero,
insetPadding: EdgeInsets.zero,
backgroundColor: Colors.white,
shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(0)),
title: widget.chart.widget.flowChart.widget.onDashboardAlertOpened!(
context, widget.dashboard));
});
}
},
child: Icon(Icons.folder, color: Colors.white))))),
])),
@@ -57,8 +60,6 @@ class FlowChartMenuState extends State<FlowChartMenu> {
),
child: Padding( padding: EdgeInsets.symmetric(horizontal: 10),
child: PopupMenuButton<DisplayEnum>(
child:
Row( children: [ Icon(Icons.fullscreen, color: Colors.white), Icon(Icons.arrow_drop_down, size: 10, color: Colors.white) ]),
initialValue: null,
onSelected: (DisplayEnum value) {
if (value == DisplayEnum.MENU) { widget.dashboard.isMenu = !widget.dashboard.isMenu; }
@@ -83,7 +84,9 @@ class FlowChartMenuState extends State<FlowChartMenu> {
child: Text(widget.dashboard.isInfo ? 'hide info' : 'show info', textAlign: TextAlign.center,))
]),
),
]
],
child:
Row( children: [ Icon(Icons.fullscreen, color: Colors.white), Icon(Icons.arrow_drop_down, size: 10, color: Colors.white) ])
),)
)
),

View File

@@ -36,10 +36,10 @@ class FlowChartSelectedMenuState extends State<FlowChartSelectedMenu> {
widget.dashboard.elements[element.elementIndex!].next.removeAt(element.connIndex!);
}
return element.isSelected;
});
widget.dashboard.removeElements((element) => element.isSelected);
}, context);
widget.dashboard.removeElements((element) => element.isSelected, context);
Future.delayed(Duration(milliseconds: 100), () {
widget.dashboard.chartKey.currentState?.setState(() { });
widget.dashboard.flutterChartKey.currentState?.setState(() { });
});
}, child: Container( margin: EdgeInsets.all(10),
decoration: BoxDecoration(borderRadius: BorderRadius.circular(5), border: Border.all(color: Colors.black, width: 1)),
@@ -51,7 +51,7 @@ class FlowChartSelectedMenuState extends State<FlowChartSelectedMenu> {
child: InkWell( mouseCursor: SystemMouseCursors.click,
onTap: () {
for (var sel in widget.dashboard.elementSelected) {
widget.dashboard.addElement(FlowElement.fromMap(widget.dashboard, sel.toMap()));
widget.dashboard.addElement(FlowElement.fromMap(widget.dashboard, sel.toMap()), context);
widget.dashboard.elements.last.position += Offset(50, 50);
}
Future.delayed(Duration(milliseconds: 100), () {
@@ -67,6 +67,42 @@ class FlowChartSelectedMenuState extends State<FlowChartSelectedMenu> {
) : Container()
])
));
} else if (widget.isDashboardInfo && widget.dashboard.arrowsSelected.length == 1) {
w = Container(
width: 200,
height: widget.height,
color: widget.dashboard.midDashColor,
child: SingleChildScrollView( child: Column( children: [
widget.dashboard.infoItemWidget != null ?
widget.dashboard.infoLinkWidget!(widget.dashboard.arrowsSelected.first) : Container(),
widget.dashboard.arrowsSelected.isNotEmpty || widget.dashboard.elementSelected.isNotEmpty ? Container(
width: 200,
margin: EdgeInsets.only(top: 15),
decoration: BoxDecoration(border: Border(
top: BorderSide(color: Colors.grey, width: 1))),
child: Column(crossAxisAlignment: CrossAxisAlignment.center, children: [
Tooltip( message: "remove",
child: InkWell( mouseCursor: SystemMouseCursors.click,
onTap: () {
widget.dashboard.removeArrows((element) {
if (element.isSelected && element.elementIndex != null && element.connIndex != null) {
widget.dashboard.elements[element.elementIndex!].next.removeAt(element.connIndex!);
}
return element.isSelected;
}, context);
Future.delayed(Duration(milliseconds: 100), () {
widget.dashboard.flutterChartKey.currentState?.setState(() { });
});
}, child: Container( margin: EdgeInsets.all(10),
decoration: BoxDecoration(borderRadius: BorderRadius.circular(5), border: Border.all(color: Colors.black, width: 1)),
width: 200, height: 30,
child: Icon(Icons.delete_outline, color: Colors.black),
))
),
])
) : Container()
])
));
} else if (widget.isDashboardInfo && widget.dashboard.infoWidget != null) {
w = Container(
width: 200,
@@ -520,10 +556,10 @@ class FlowChartSelectedMenuState extends State<FlowChartSelectedMenu> {
widget.dashboard.elements[element.elementIndex!].next.removeAt(element.connIndex!);
}
return element.isSelected;
});
widget.dashboard.removeElements((element) => element.isSelected);
}, context);
widget.dashboard.removeElements((element) => element.isSelected, context);
Future.delayed(Duration(milliseconds: 100), () {
widget.dashboard.chartKey.currentState?.setState(() { });
widget.dashboard.flutterChartKey.currentState?.setState(() { });
});
}, child: Container( margin: EdgeInsets.all(10),
decoration: BoxDecoration(borderRadius: BorderRadius.circular(5), border: Border.all(color: Colors.black, width: 1)),
@@ -535,7 +571,7 @@ class FlowChartSelectedMenuState extends State<FlowChartSelectedMenu> {
child: InkWell( mouseCursor: SystemMouseCursors.click,
onTap: () {
for (var sel in widget.dashboard.elementSelected) {
widget.dashboard.addElement(FlowElement.fromMap(widget.dashboard, sel.toMap()));
widget.dashboard.addElement(FlowElement.fromMap(widget.dashboard, sel.toMap()), context);
widget.dashboard.elements.last.position += Offset(50, 50);
}
Future.delayed(Duration(milliseconds: 100), () {

View File

@@ -211,6 +211,8 @@ class DrawingArrow extends ChangeNotifier {
/// Arrow parameters.
ArrowParams params = ArrowParams();
List<dynamic> env = [];
List<dynamic> infos = [];
String fromID = "";
String toID = "";
@@ -264,13 +266,16 @@ class DrawArrow extends StatefulWidget {
required this.srcElement,
required this.destElement,
required List<Pivot> pivots,
this.infos = const [],
this.env = const [],
super.key,
ArrowParams? arrowParams,
}) : arrowParams = arrowParams ?? ArrowParams(),
pivots = PivotsNotifier(pivots);
final int index;
List<dynamic> env = [];
List<dynamic> infos = [];
///
final ArrowParams arrowParams;
@@ -340,6 +345,8 @@ class DrawArrowState extends State<DrawArrow> {
builder: (context) {
var painter = ArrowPainter(
connIndex: widget.index,
infos: widget.infos,
env: widget.env,
elementIndex: widget.flow.widget.dashboard.elements.indexOf(widget.srcElement),
fromID: "${widget.srcElement.id}_${widget.index}",
toID: "${widget.destElement.id}_${widget.index}",
@@ -351,8 +358,8 @@ class DrawArrowState extends State<DrawArrow> {
);
if ( widget.flow.widget.dashboard.arrows.where(
(element) => element.fromID == "${widget.srcElement.id}_${widget.index}").isEmpty) {
widget.flow.widget.dashboard.addArrows(painter);
widget.flow.widget.dashboard.saveDash(widget.flow.widget.dashboard.id);
widget.flow.widget.dashboard.addArrows(painter, context);
widget.flow.widget.dashboard.saveDash(widget.flow.widget.dashboard.id, context);
} else {
var i = widget.flow.widget.dashboard.arrows.indexWhere(
(element) => element.fromID == "${widget.srcElement.id}_${widget.index}");
@@ -390,7 +397,7 @@ class GraphParamsWidgetState extends State<GraphParamsWidget> {
child: Row(children: [
IconButton(onPressed: () {
widget.comp.setState(() {
widget.comp.widget.dashboard.removeArrows((el) => el.fromID == "${widget.element.id}${widget.index}");
widget.comp.widget.dashboard.removeArrows((el) => el.fromID == "${widget.element.id}${widget.index}", context);
widget.element.next.removeAt(widget.index);
});
}, icon: Icon(Icons.delete))
@@ -421,13 +428,13 @@ class ArrowInfoWidgetState extends State<ArrowInfoWidget> {
/// [ArrowParams.startArrowPosition] and
/// [ArrowParams.endArrowPosition] alignment.
class ArrowPainter extends CustomPainter {
///
ArrowPainter({
this.elementIndex,
this.connIndex,
this.toID = "",
this.fromID = "",
this.infos = const [],
this.env = const [],
this.isSelected = false,
required this.params,
this.from = Offset.zero,
@@ -435,9 +442,9 @@ class ArrowPainter extends CustomPainter {
List<Pivot>? pivots,
}) : pivots = pivots ?? [];
///
List<dynamic> env;
List<dynamic> infos;
ArrowParams params;
///
String toID;
String fromID;
Offset to;
@@ -462,6 +469,8 @@ class ArrowPainter extends CustomPainter {
final arrowAngle= 25 * math.pi / 180;
ArrowPainter deserialize(Map<String, dynamic> map) {
infos = map['infos'];
env = map['env'];
params = ArrowParams.fromMap(map['params']);
fromID = map['from']['id'];
toID = map['to']['id'];
@@ -469,9 +478,10 @@ class ArrowPainter extends CustomPainter {
to = Offset(map['to']['x'], map['to']['y']);
return this;
}
Map<String, dynamic> serialize() {
Map<String, dynamic> graphElement = {};
graphElement['infos'] = infos;
graphElement['env'] = env;
graphElement['from'] = { "id" : fromID.split("_")[0], "x" : from.dx, "y" : from.dy };
graphElement['to'] = { "id" : toID.split("_")[0], "x" : to.dx, "y" : to.dy };
graphElement['params'] = params.toMap();
@@ -484,6 +494,8 @@ class ArrowPainter extends CustomPainter {
elementIndex: map['elementIndex'] as int,
toID: map['toID'] != null ? map['toID'] as String : "",
fromID: map['fromID'] as String,
infos: map['infos'] as List,
env: map['env'] as List,
isSelected: map['isSelected'] != null ? map['isSelected'] as bool : false,
params: ArrowParams.fromMap(map['params']),
from: Offset(
@@ -511,6 +523,8 @@ class ArrowPainter extends CustomPainter {
"fromDy" : from.dy,
"toDx" : to.dx,
"toDy" : to.dy,
"infos" : infos,
"env" : env,
'pivots': pivots.map((e) => e.toMap()).toList(),
};
}

View File

@@ -151,12 +151,15 @@ class ElementWidgetState<T extends FlowData> extends State<ElementWidget> {
for (var element in widget.dashboard.elements) {
element.isSelected = false;
element.dashboard.chartKey.currentState?. setState(() { });
widget.dashboard.selectedMenuKey.currentState?. setState(() { });
}
}
widget.element.isSelected = !widget.element.isSelected;
for (var sel in widget.dashboard.arrows) { sel.isSelected = false; }
widget.dashboard.selectedMenuKey.currentState?. setState(() { });
Future.delayed(Duration(seconds: 1), () { DrawingArrow.instance.notifyListeners(); });
Future.delayed(Duration(milliseconds: 100), () {
DrawingArrow.instance.notifyListeners();
widget.element.isSelected = !widget.element.isSelected;
for (var sel in widget.dashboard.arrows) { sel.isSelected = false; }
widget.dashboard.selectedMenuKey.currentState?. setState(() { });
});
});
widget.onElementPressed?.call(context, tapLocation);
},
@@ -234,7 +237,7 @@ class ElementWidgetState<T extends FlowData> extends State<ElementWidget> {
sel.changePosition(sel.position + diff);
}
}
widget.dashboard.save!(widget.dashboard.id);
widget.dashboard.saveDash(widget.dashboard.id, context);
},
),
),
@@ -263,7 +266,7 @@ class ElementWidgetState<T extends FlowData> extends State<ElementWidget> {
child: Row( mainAxisAlignment: MainAxisAlignment.center,
children: (!widget.isHovered ? [] : [
IconButton(tooltip: "remove element", onPressed: () {
widget.dashboard.removeElement(widget.element);
widget.dashboard.removeElement(widget.element, context);
}, icon: Icon(Icons.delete_outline)),
IconButton(tooltip: "copy element", onPressed: () {
FlowElement<T> newElement = FlowElement<T>(
@@ -274,7 +277,7 @@ class ElementWidgetState<T extends FlowData> extends State<ElementWidget> {
size: widget.element.size,
widget: widget.element.widget,
);
widget.dashboard.addElement(newElement);
widget.dashboard.addElement(newElement, context);
}, icon: Icon(Icons.copy, size: 20)),
]))
),