From b941d8f1dec3661bc7ef1ae610c2b4a4a9581aef Mon Sep 17 00:00:00 2001 From: Arthur Heitmann Date: Fri, 7 Oct 2022 19:44:42 +0200 Subject: [PATCH] added condition prop editor --- lib/widgets/EditorLayout.dart | 2 +- .../customXmlProps/conditionEditor.dart | 75 +++++++++++++++++++ .../simpleProps/XmlPropEditorFactory.dart | 5 ++ 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 lib/widgets/propEditors/customXmlProps/conditionEditor.dart diff --git a/lib/widgets/EditorLayout.dart b/lib/widgets/EditorLayout.dart index 2544d721..f73f398b 100644 --- a/lib/widgets/EditorLayout.dart +++ b/lib/widgets/EditorLayout.dart @@ -16,7 +16,7 @@ class EditorLayout extends StatelessWidget { return LayoutBuilder(builder: (context, constraints) { return ResizableWidget( axis: Axis.horizontal, - percentages: [0.18, 0.60, 0.22], + percentages: [0.22, 0.53, 0.25], draggableThickness: 4, lineThickness: 4, children: [ diff --git a/lib/widgets/propEditors/customXmlProps/conditionEditor.dart b/lib/widgets/propEditors/customXmlProps/conditionEditor.dart new file mode 100644 index 00000000..a0f6e975 --- /dev/null +++ b/lib/widgets/propEditors/customXmlProps/conditionEditor.dart @@ -0,0 +1,75 @@ + +import 'package:flutter/material.dart'; + +import '../../../customTheme.dart'; +import '../../../stateManagement/ChangeNotifierWidget.dart'; +import '../../../stateManagement/xmlProps/xmlProp.dart'; +import '../simpleProps/XmlPropEditorFactory.dart'; +import '../simpleProps/propEditorFactory.dart'; +import 'puidReferenceEditor.dart'; + +class ConditionEditor extends ChangeNotifierWidget { + final XmlProp prop; + final bool showDetails; + + ConditionEditor({super.key, required this.prop, required this.showDetails}) : super(notifier: prop); + + @override + State createState() => _ConditionEditorState(); +} + +class _ConditionEditorState extends ChangeNotifierState { + @override + Widget build(BuildContext context) { + var label = widget.prop.get("condition")?.get("state")?.get("label")?.value; + var value = widget.prop.get("condition")?.get("state")?.get("value"); + var args = widget.prop.get("args"); + + return Padding( + padding: const EdgeInsets.all(4.0), + child: Row( + children: [ + // Icon(Icons.help), + Text( + "?", + style: TextStyle(fontSize: 30, fontWeight: FontWeight.bold), + ), + SizedBox(width: 12), + Expanded( + child: Container( + decoration: BoxDecoration( + color: getTheme(context).formElementBgColor, + borderRadius: BorderRadius.circular(5), + ), + padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + PuidReferenceEditor(prop: widget.prop.get("puid")!, showDetails: widget.showDetails), + Divider(color: getTheme(context).textColor!.withOpacity(0.75), thickness: 2,), + if (label != null) + makePropEditor(label) + else + Text("No label"), + if (value != null) + Padding( + padding: const EdgeInsets.only(left: 8.0), + child: makeXmlPropEditor(value, widget.showDetails), + ), + if (args != null) + Padding( + padding: const EdgeInsets.only(left: 8.0), + child: makeXmlPropEditor(args, widget.showDetails), + ), + ], + ), + ), + ) + ] + ), + ); + } +} + + diff --git a/lib/widgets/propEditors/simpleProps/XmlPropEditorFactory.dart b/lib/widgets/propEditors/simpleProps/XmlPropEditorFactory.dart index c81cbef5..a621a3d4 100644 --- a/lib/widgets/propEditors/simpleProps/XmlPropEditorFactory.dart +++ b/lib/widgets/propEditors/simpleProps/XmlPropEditorFactory.dart @@ -6,6 +6,7 @@ import '../../../stateManagement/Property.dart'; import '../../../stateManagement/xmlProps/xmlProp.dart'; import '../../../utils.dart'; import '../customXmlProps/areaEditor.dart'; +import '../customXmlProps/conditionEditor.dart'; import '../customXmlProps/entityEditor.dart'; import '../customXmlProps/layoutsEditor.dart'; import '../customXmlProps/paramEditor.dart'; @@ -31,6 +32,10 @@ Widget makeXmlPropEditor(XmlProp prop, bool showDetails if (prop.length == 3 && prop[0].tagName == "name" && prop[1].tagName == "code" && prop[2].tagName == "body") { return ParamsEditor(prop: prop, showDetails: showDetails); } + // condition + if (prop.get("puid") != null && prop.get("condition") != null) { + return ConditionEditor(prop: prop, showDetails: showDetails); + } // fallback return XmlPropEditor(prop: prop, showDetails: showDetails,); }