Latest Front with debug

This commit is contained in:
mr
2024-08-30 12:52:32 +02:00
parent 8beddba367
commit 0b294a782c
42 changed files with 1367 additions and 925 deletions

View File

@@ -23,6 +23,7 @@ typedef ConnectionListener = void Function(
/// It notifies changes to [FlowChart]
//
class Dashboard extends ChangeNotifier {
bool shouldSave = true;
GlobalKey<FlowChartSelectedMenuState> selectedMenuKey = GlobalKey<FlowChartSelectedMenuState>();
GlobalKey<FlowChartLeftMenuState> selectedLeftMenuKey = GlobalKey<FlowChartLeftMenuState>();
GlobalKey<FlowChartMenuState> chartMenuKey = GlobalKey<FlowChartMenuState>();
@@ -49,6 +50,7 @@ class Dashboard extends ChangeNotifier {
List<Widget> Function(FlowData? obj)? infoItemWidget;
List<Widget> Function()? infoWidget;
FlowData? Function(Map<String, dynamic> json)? transformToData;
bool addChange = false;
///
Dashboard({
this.id,
@@ -91,7 +93,6 @@ class Dashboard extends ChangeNotifier {
}
tempHistory = [];
history = [];
addToHistory();
}
Future<void> Function(String cat)? load;
@@ -267,6 +268,7 @@ class Dashboard extends ChangeNotifier {
}
selectedMenuKey.currentState?.setState(() { });
chartMenuKey.currentState?.setState(() { });
addToHistory();
}
/// add listener called when a new connection is created
@@ -291,21 +293,62 @@ class Dashboard extends ChangeNotifier {
handlerFeedbackOffset = offset;
}
void addArrows(ArrowPainter f) {
arrows.add(f);
addChange = true;
if (save != null) {
save!(id);
}
}
void removeArrows(bool Function(ArrowPainter) f) {
arrows.removeWhere((element) => f(element));
if (save != null) {
save!(id);
}
}
void removeElements(bool Function(FlowElement<FlowData>) f) {
elements.removeWhere((element) => f(element));
if (save != null) {
save!(id);
}
}
void clear() {
elements.clear();
arrows.clear();
tempHistory = [];
history = [];
scheduler = {};
info = {};
scheduleActive = false;
notifyListeners();
}
bool noHistory = false;
void addToHistory() {
if (noHistory) {
Future.delayed(Duration(seconds: 2), () {
noHistory = false;
});
return;
}
if (tempHistory.length >= 50) { tempHistory.removeAt(0); }
tempHistory.add(toMap());
if (save != null) { save!(id); }
history = tempHistory.map((e) => e).toList();
chartKey.currentState?.setState(() { });
chartMenuKey.currentState?.setState(() { });
}
bool isBack = false;
void back() {
tempHistory.removeLast();
if (tempHistory.length == 0) return;
copyFromMap(tempHistory.last);
chartKey.currentState?.setState(() { });
chartMenuKey.currentState?.setState(() { });
if (canBack()) {
noHistory = true;
tempHistory.removeLast();
if (tempHistory.length > 0) {
copyFromMap(tempHistory.last);
}
chartKey.currentState?.setState(() { });
chartMenuKey.currentState?.setState(() { });
}
}
bool canBack() {
@@ -318,6 +361,7 @@ class Dashboard extends ChangeNotifier {
void forward() {
if (canForward()) {
noHistory = true;
tempHistory.add(history[tempHistory.length]);
copyFromMap(tempHistory.last);
chartKey.currentState?.setState(() { });
@@ -332,6 +376,9 @@ class Dashboard extends ChangeNotifier {
bool notify = true,
}) {
element.isResizing = resizable;
if (save != null) {
save!(id);
}
if (notify) notifyListeners();
}
@@ -347,6 +394,10 @@ class Dashboard extends ChangeNotifier {
}
element.setScale(1, gridBackgroundParams.scale);
elements.add(element);
addChange = true;
if (save != null) {
save!(id);
}
if (notify) {
notifyListeners();
}
@@ -361,7 +412,6 @@ class Dashboard extends ChangeNotifier {
@override
void notifyListeners() {
addToHistory();
super.notifyListeners();
}

View File

@@ -107,6 +107,7 @@ class FlowElement<T extends FlowData> extends ChangeNotifier {
return false;
}
factory FlowElement.fromMap(Dashboard dashboard, Map<String, dynamic> map) {
print("FlowElement.fromMap ${map}");
final e = FlowElement<T>(
element: (dashboard.transformToData != null
? dashboard.transformToData!(map['element'] ?? {})
@@ -341,6 +342,7 @@ class FlowElement<T extends FlowData> extends ChangeNotifier {
Map<String, dynamic> toMap() {
return <String, dynamic>{
'widget': widget,
'element': element?.serialize(),
'positionDx': position.dx,
'positionDy': position.dy,
'size.width': size.width,

View File

@@ -56,8 +56,10 @@ class FlowChart<T extends FlowData> extends StatefulWidget {
required this.draggableItemBuilder,
this.onDashboardAlertOpened,
this.menuWidget,
this.current,
this.menuExtension,
}) {}
final String? current;
final List<String> categories;
final double width;
final double height;
@@ -303,18 +305,25 @@ class FlowChartState<T extends FlowData> extends State<FlowChart> {
@override
Widget build(BuildContext context) {
if (!widget.dashboard.isOpened && widget.onDashboardAlertOpened != null ) {
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.id != null) {
widget.dashboard.isOpened = true;
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));
}); });
}
} else {
widget.dashboard.isOpened = true;
}
/// get dashboard position after first frame is drawn
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
@@ -371,7 +380,7 @@ class FlowChartState<T extends FlowData> extends State<FlowChart> {
if (event is KeyDownEvent && event.logicalKey == LogicalKeyboardKey.add) {
change = true;
for (var el in widget.dashboard.elementSelected) {
widget.dashboard.elements.add(FlowElement<T>(
widget.dashboard.addElement(FlowElement<T>(
element: el.element as T,
dashboard: widget.dashboard,
id: const Uuid().v4(),
@@ -387,13 +396,13 @@ class FlowChartState<T extends FlowData> extends State<FlowChart> {
}
if (event is KeyDownEvent && event.logicalKey == LogicalKeyboardKey.delete) {
change = true;
widget.dashboard.elements.removeWhere( (el) => el.isSelected );
widget.dashboard.removeElements( (el) => el.isSelected );
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.arrows.removeWhere( (el) => el.isSelected );
widget.dashboard.removeArrows( (el) => el.isSelected );
}
if (change) {
DrawingArrow.instance.notifyListeners();
@@ -466,11 +475,11 @@ class FlowChartState<T extends FlowData> extends State<FlowChart> {
widget.dashboard.isMenu ? Positioned(top: 50, child: FlowChartLeftMenu<T>(
key: widget.dashboard.selectedLeftMenuKey,
dashboard: widget.dashboard,
menuExtension: widget.menuExtension,
categories: widget.categories,
height: widget.height,
innerMenuWidth: widget.innerMenuWidth,
itemWidth: widget.itemWidth,
menuExtension: widget.menuExtension,
draggableItemBuilder: widget.draggableItemBuilder as List<T> Function(String cat),
getDraggable: getDraggable,
) )
@@ -745,7 +754,7 @@ class ChartWidgetState<T extends FlowData> extends State<ChartWidget> {
if (!hoverImportant) {
for (var sel in widget.dashboard.elements) { sel.isSelected = false; }
for (var sel in widget.dashboard.arrows) { sel.isSelected = false; }
Future.delayed(Duration(seconds: 1), () {
Future.delayed(Duration(milliseconds: 100), () {
widget.dashboard.selectedMenuKey.currentState?.setState(() {});
DrawingArrow.instance.notifyListeners();
});

View File

@@ -69,7 +69,9 @@ class FlowChartLeftMenuState<T extends FlowData> extends State<FlowChartLeftMenu
Container(
width: widget.innerMenuWidth,
height: 50,
decoration: const BoxDecoration(border: Border(left: BorderSide(color: Colors.white))),
decoration: BoxDecoration(border: Border(
right: BorderSide(color: Colors.grey.shade300),
left: BorderSide(color: Colors.white))),
child: TextFormField(
style: const TextStyle(color: Colors.black, fontSize: 15),
cursorColor: const Color.fromARGB(38, 166, 154, 1),

View File

@@ -20,7 +20,7 @@ class FlowChartSelectedMenuState extends State<FlowChartSelectedMenu> {
width: 250,
height: widget.height,
color: Colors.grey.shade300,
child: Column( children: [ ...widget.dashboard.infoItemWidget != null ?
child: SingleChildScrollView( child: Column( children: [ ...widget.dashboard.infoItemWidget != null ?
widget.dashboard.infoItemWidget!(widget.dashboard.elementSelected.first.element)
: [],
widget.dashboard.arrowsSelected.isNotEmpty || widget.dashboard.elementSelected.isNotEmpty ? Container(
@@ -33,13 +33,13 @@ class FlowChartSelectedMenuState extends State<FlowChartSelectedMenu> {
Tooltip( message: "remove",
child: InkWell( mouseCursor: SystemMouseCursors.click,
onTap: () {
widget.dashboard.arrows.removeWhere((element) {
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;
});
widget.dashboard.elements.removeWhere((element) => element.isSelected);
widget.dashboard.removeElements((element) => element.isSelected);
Future.delayed(Duration(milliseconds: 100), () {
widget.dashboard.chartKey.currentState?.setState(() { });
});
@@ -53,13 +53,13 @@ class FlowChartSelectedMenuState extends State<FlowChartSelectedMenu> {
child: InkWell( mouseCursor: SystemMouseCursors.click,
onTap: () {
for (var sel in widget.dashboard.elementSelected) {
widget.dashboard.elements.add(FlowElement.fromMap(widget.dashboard, sel.toMap()));
widget.dashboard.addElement(FlowElement.fromMap(widget.dashboard, sel.toMap()));
widget.dashboard.elements.last.position += Offset(50, 50);
}
Future.delayed(Duration(milliseconds: 100), () {
widget.dashboard.chartKey.currentState?.setState(() { });
});
}, child: Container( margin: EdgeInsets.all(10),
}, child: Container( margin: EdgeInsets.only(left: 10, right: 10),
decoration: BoxDecoration(borderRadius: BorderRadius.circular(5), border: Border.all(color: Colors.black, width: 1)),
width: 200, height: 30,
child: Icon(Icons.copy, color: Colors.black),
@@ -68,7 +68,7 @@ class FlowChartSelectedMenuState extends State<FlowChartSelectedMenu> {
])
) : Container()
])
);
));
} else if (widget.isDashboardInfo && widget.dashboard.infoWidget != null) {
w = Container(
width: 250,
@@ -100,7 +100,7 @@ class FlowChartSelectedMenuState extends State<FlowChartSelectedMenu> {
constraints: BoxConstraints(maxWidth: 100),
child: Row( children: [
MySeparator(
width: 45,
width: 65,
dashWidth: widget.dashboard.defaultDashWidth,
dashSpace: widget.dashboard.defaultDashSpace,
color: Colors.black
@@ -193,7 +193,7 @@ class FlowChartSelectedMenuState extends State<FlowChartSelectedMenu> {
Tooltip( message: "stroke width",
child: Container(
margin: EdgeInsets.only(left: 10),
width: 45, height: 25,
width: 75, height: 25,
child: TextFormField( textAlign: TextAlign.center,
readOnly: widget.dashboard.defaultDashWidth <= 0,
initialValue: "${widget.dashboard.defaultStroke}",
@@ -280,7 +280,7 @@ class FlowChartSelectedMenuState extends State<FlowChartSelectedMenu> {
Tooltip( message: "space dash",
child: Container(
margin: EdgeInsets.only(top: 10),
width: 105 / 2, height: 25,
width: 155 / 2, height: 25,
child: TextFormField( textAlign: TextAlign.center,
readOnly: widget.dashboard.defaultDashWidth <= 0,
initialValue: "${widget.dashboard.defaultDashWidth}",
@@ -318,7 +318,7 @@ class FlowChartSelectedMenuState extends State<FlowChartSelectedMenu> {
Tooltip( message: "space width",
child: Container(
margin: EdgeInsets.only(left: 10, top: 10),
width: 105 / 2, height: 25,
width: 155 / 2, height: 25,
child: TextFormField( textAlign: TextAlign.center,
initialValue: "${widget.dashboard.defaultDashSpace}",
onChanged: (value) {
@@ -414,7 +414,7 @@ class FlowChartSelectedMenuState extends State<FlowChartSelectedMenu> {
Tooltip( message: "forward size",
child: Container(
margin: EdgeInsets.only(left: 10, top: 10),
width: 135, height: 25,
width: 185, height: 25,
child: TextFormField( textAlign: TextAlign.center,
initialValue: "${widget.dashboard.defaultForwardWidth}",
onChanged: (value) {
@@ -466,7 +466,7 @@ class FlowChartSelectedMenuState extends State<FlowChartSelectedMenu> {
Tooltip( message: "back size",
child: Container(
margin: EdgeInsets.only(left: 10, top: 10),
width: 135, height: 25,
width: 185, height: 25,
child: TextFormField( textAlign: TextAlign.center,
initialValue: "${widget.dashboard.defaultBackWidth}",
onChanged: (value) {
@@ -522,13 +522,13 @@ class FlowChartSelectedMenuState extends State<FlowChartSelectedMenu> {
Tooltip( message: "remove",
child: InkWell( mouseCursor: SystemMouseCursors.click,
onTap: () {
widget.dashboard.arrows.removeWhere((element) {
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;
});
widget.dashboard.elements.removeWhere((element) => element.isSelected);
widget.dashboard.removeElements((element) => element.isSelected);
Future.delayed(Duration(milliseconds: 100), () {
widget.dashboard.chartKey.currentState?.setState(() { });
});
@@ -542,7 +542,7 @@ class FlowChartSelectedMenuState extends State<FlowChartSelectedMenu> {
child: InkWell( mouseCursor: SystemMouseCursors.click,
onTap: () {
for (var sel in widget.dashboard.elementSelected) {
widget.dashboard.elements.add(FlowElement.fromMap(widget.dashboard, sel.toMap()));
widget.dashboard.addElement(FlowElement.fromMap(widget.dashboard, sel.toMap()));
widget.dashboard.elements.last.position += Offset(50, 50);
}
Future.delayed(Duration(milliseconds: 100), () {

View File

@@ -226,6 +226,7 @@ class DrawingArrow extends ChangeNotifier {
///
void setFrom(Offset from) {
this.from = from;
notifyListeners();
}
@@ -350,7 +351,7 @@ 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.arrows.add(painter);
widget.flow.widget.dashboard.addArrows(painter);
widget.flow.widget.dashboard.save!(widget.flow.widget.dashboard.id);
} else {
var i = widget.flow.widget.dashboard.arrows.indexWhere(
@@ -481,9 +482,9 @@ class ArrowPainter extends CustomPainter {
final e = ArrowPainter(
connIndex: map['connIndex'] as int,
elementIndex: map['elementIndex'] as int,
toID: map['toID'] as String,
toID: map['toID'] != null ? map['toID'] as String : "",
fromID: map['fromID'] as String,
isSelected: map['isSelected'] as bool,
isSelected: map['isSelected'] != null ? map['isSelected'] as bool : false,
params: ArrowParams.fromMap(map['params']),
from: Offset(
map['fromDx'] as double,
@@ -500,14 +501,17 @@ class ArrowPainter extends CustomPainter {
Map<String, dynamic> toMap() {
return {
'toID': toID,
'fromID': fromID,
'elementIndex': elementIndex,
'connIndex': connIndex,
'isSelected': isSelected.toString(),
'params': params.toJson(),
'from': from.toString(),
'to': to.toString(),
'pivots': json.encode(pivots.map((e) => e.toMap()).toList()),
'isSelected': isSelected,
'params': params.toMap(),
"fromDx" : from.dx,
"fromDy" : from.dy,
"toDx" : to.dx,
"toDy" : to.dy,
'pivots': pivots.map((e) => e.toMap()).toList(),
};
}