@@ -13,123 +13,120 @@ class PassiveCheckboxTransformer extends NodeWidgetTransformer<CheckboxNode> {
1313 BuildContext context,
1414 WidgetBuildSettings settings,
1515 ) {
16- return buildFromNode (context, node, settings: settings);
17- }
18-
19- Widget buildFromProps (
20- BuildContext context, {
21- required CheckboxProperties props,
22- required double height,
23- required double width,
24- bool ? value,
25- required WidgetBuildSettings settings,
26- }) {
27- final node = CheckboxNode (
28- id: '' ,
29- name: 'Checkbox' ,
30- basicBoxLocal: NodeBox (0 , 0 , width, height),
31- alignment: AlignmentModel .none,
32- properties: props,
33- )..value = value;
34- return buildFromNode (context, node, settings: settings);
16+ if (settings.isPreview) {
17+ bool ? effectiveValue = node.value;
18+ return StatefulBuilder (
19+ builder: (context, setState) => TransformerCheckbox (
20+ node: node,
21+ settings: settings,
22+ onChanged: (context, value) => setState (() {
23+ effectiveValue = value;
24+ }),
25+ value: effectiveValue,
26+ ),
27+ );
28+ } else {
29+ return PassiveCheckboxWidget (
30+ node: node,
31+ settings: settings,
32+ );
33+ }
3534 }
35+ }
3636
37- Widget buildPreview ({
38- CheckboxProperties ? properties,
39- CheckboxNode ? node,
40- double ? height,
41- double ? width,
42- bool ? value,
43- ValueChanged <bool ?>? onChanged,
44- WidgetBuildSettings settings =
45- const WidgetBuildSettings (debugLabel: 'buildPreview' ),
46- }) {
47- final previewNode = CheckboxNode (
48- properties: properties ?? node? .properties ?? CheckboxProperties (),
49- id: '' ,
50- name: 'Checkbox' ,
51- basicBoxLocal: NodeBox (0 , 0 , width ?? 32 , height ?? 32 ),
52- retainedOuterBoxLocal: NodeBox (0 , 0 , width ?? 32 , height ?? 32 ),
53- );
54- previewNode.value = value;
55- return PassiveCheckboxWidget (
56- node: previewNode,
57- onChanged: (context, value) => onChanged? .call (value),
58- settings: settings,
59- );
60- }
37+ class PassiveCheckboxWidget extends StatelessWidget {
38+ final CheckboxNode node;
39+ final WidgetBuildSettings settings;
40+ final List <VariableData > variables;
6141
62- Widget buildFromNode (
63- BuildContext context,
64- CheckboxNode node, {
65- required WidgetBuildSettings settings,
66- }) {
67- return PassiveCheckboxWidget (
68- node: node,
69- settings: settings,
70- onChanged: (context, value) => onChanged (context, node, value),
71- );
72- }
42+ const PassiveCheckboxWidget ({
43+ super .key,
44+ required this .node,
45+ required this .settings,
46+ this .variables = const [],
47+ });
7348
74- void onChanged (BuildContext context, CheckboxNode node, bool ? internalValue) {
49+ void onChanged (BuildContext context, bool ? internalValue) {
7550 NodeStateProvider .setState (context, internalValue);
51+
7652 FunctionsRepository .setPropertyValue (context,
7753 node: node, property: 'value' , value: internalValue);
78-
7954 FunctionsRepository .triggerAction (
8055 context, node: node, TriggerType .changed, value: internalValue);
8156 }
57+
58+ @override
59+ Widget build (BuildContext context) {
60+ final bool ? value = PropertyValueDelegate .getPropertyValue <bool >(
61+ node,
62+ 'value' ,
63+ scopedValues: ScopedValues .of (context, variablesOverrides: variables),
64+ ) ??
65+ node.value;
66+
67+ return TransformerCheckbox (
68+ node: node,
69+ settings: settings,
70+ value: value,
71+ onChanged: onChanged,
72+ variables: variables,
73+ );
74+ }
8275}
8376
84- class PassiveCheckboxWidget extends StatelessWidget {
77+ class TransformerCheckbox extends StatefulWidget {
8578 final CheckboxNode node;
8679 final WidgetBuildSettings settings;
8780 final List <VariableData > variables;
8881 final void Function (BuildContext context, bool ? value)? onChanged;
82+ final bool ? value;
8983
90- const PassiveCheckboxWidget ({
84+ const TransformerCheckbox ({
9185 super .key,
9286 required this .node,
9387 required this .settings,
9488 required this .onChanged,
89+ required this .value,
9590 this .variables = const [],
9691 });
9792
9893 @override
99- Widget build (BuildContext context) {
100- final double scale = node.basicBoxLocal.width /
101- (node.properties.compact ? Checkbox .width : kCheckboxDefaultSize);
94+ State <TransformerCheckbox > createState () => _TransformerCheckboxState ();
95+ }
10296
103- final bool ? value = PropertyValueDelegate .getPropertyValue <bool >(
104- node,
105- 'value' ,
106- scopedValues: ScopedValues .of (context, variablesOverrides: variables),
107- ) ??
108- node.value;
97+ class _TransformerCheckboxState extends State <TransformerCheckbox > {
98+ @override
99+ Widget build (BuildContext context) {
100+ final double scale = widget.node.basicBoxLocal.width /
101+ (widget.node.properties.compact
102+ ? Checkbox .width
103+ : kCheckboxDefaultSize);
109104
110105 return SizedBox .fromSize (
111- size: node.basicBoxLocal.size.flutterSize,
106+ size: widget. node.basicBoxLocal.size.flutterSize,
112107 child: Transform .scale (
113108 scale: scale,
114109 child: Checkbox (
115110 key: ValueKey (
116- '${node .id }-${IndexedItemProvider .maybeOf (context )?.index ?? '' }' ),
117- value: node.properties.tristate ? value : (value ?? false ),
118- tristate: node.properties.tristate,
119- autofocus: node.properties.autofocus,
120- checkColor: node.properties.checkColor.toFlutterColor (),
121- activeColor: node.properties.activeColor.toFlutterColor (),
122- hoverColor: node.properties.hoverColor.toFlutterColor (),
123- focusColor: node.properties.focusColor.toFlutterColor (),
124- onChanged: (value) => onChanged? .call (context, value),
111+ '${widget .node .id }-${IndexedItemProvider .maybeOf (context )?.index ?? '' }' ),
112+ value: widget.node.properties.tristate
113+ ? widget.value
114+ : (widget.value ?? false ),
115+ tristate: widget.node.properties.tristate,
116+ autofocus: widget.node.properties.autofocus,
117+ checkColor: widget.node.properties.checkColor.toFlutterColor (),
118+ activeColor: widget.node.properties.activeColor.toFlutterColor (),
119+ hoverColor: widget.node.properties.hoverColor.toFlutterColor (),
120+ focusColor: widget.node.properties.focusColor.toFlutterColor (),
121+ onChanged: (value) => widget.onChanged? .call (context, value),
125122 visualDensity: VisualDensity .standard,
126- splashRadius: node.properties.splashRadius,
123+ splashRadius: widget. node.properties.splashRadius,
127124 shape: RoundedRectangleBorder (
128- borderRadius: node.properties.cornerRadius.borderRadius,
125+ borderRadius: widget. node.properties.cornerRadius.borderRadius,
129126 ),
130127 side: BorderSide (
131- color: node.properties.borderColor.toFlutterColor (),
132- width: node.properties.borderWidth,
128+ color: widget. node.properties.borderColor.toFlutterColor (),
129+ width: widget. node.properties.borderWidth,
133130 ),
134131 ),
135132 ),
0 commit comments