@@ -5,6 +5,11 @@ import 'package:flutter/material.dart';
55import '../../../codelessly_sdk.dart' ;
66import '../../functions/functions_repository.dart' ;
77
8+ typedef TriggerAction = void Function (
9+ BuildContext context,
10+ List <Reaction > reactions,
11+ );
12+
813class PassiveAppBarTransformer extends NodeWidgetTransformer <AppBarNode > {
914 PassiveAppBarTransformer (super .getNode, super .manager);
1015
@@ -21,8 +26,7 @@ class PassiveAppBarTransformer extends NodeWidgetTransformer<AppBarNode> {
2126 return PassiveAppBarWidget (
2227 node: node,
2328 settings: settings,
24- onLeadingPressed: onTriggerAction,
25- onActionPressed: onTriggerAction,
29+ onTriggerAction: onTriggerAction,
2630 );
2731 }
2832
@@ -37,60 +41,91 @@ class PassiveAppBarTransformer extends NodeWidgetTransformer<AppBarNode> {
3741 }) {
3842 final Widget ? leading = node.properties.leading.icon.show &&
3943 ! node.properties.automaticallyImplyLeading
40- ? retrieveIconWidget (node.properties.leading.icon, null )
44+ ? retrieveIconWidget (
45+ node.properties.leading.icon,
46+ node.properties.leading.icon.size,
47+ )
4148 : null ;
4249
4350 final Widget ? title = node.properties.title.trim ().isEmpty
4451 ? null
4552 : TextUtils .buildText (
4653 context,
4754 node.properties.title,
48- textAlignHorizontal: null ,
49- maxLines: null ,
50- overflow: null ,
55+ fontSize: node.properties.titleStyle.fontSize,
5156 node: node,
5257 variablesOverrides: variablesOverrides,
5358 nullSubstitutionMode: settings.nullSubstitutionMode,
5459 replaceVariablesWithSymbol: settings.replaceVariablesWithSymbols,
5560 );
5661 return AppBar (
5762 centerTitle: node.properties.centerTitle,
63+ automaticallyImplyLeading: node.properties.leading.icon.show
64+ ? node.properties.automaticallyImplyLeading
65+ : false ,
5866 leading: leading != null
59- ? IconButton (
60- onPressed: () => onTriggerAction.call (
61- context, node.properties.leading.reactions),
62- icon: leading,
67+ ? Center (
68+ child: buildIconOrButton (
69+ context,
70+ icon: leading,
71+ size: node.properties.leading.icon.size,
72+ tooltip: node.properties.leading.tooltip,
73+ reactions: node.properties.leading.reactions,
74+ ),
6375 )
6476 : null ,
77+ title: title,
6578 titleTextStyle: TextUtils .retrieveTextStyleFromProp (
6679 node.properties.titleStyle,
6780 effects: const [],
6881 ),
82+ titleSpacing: node.properties.titleSpacing,
83+ // TODO(Saad,Birju): Make surfaceTintColor a property of the AppBarNode.
84+ surfaceTintColor: node.properties.backgroundColor.toFlutterColor (),
6985 backgroundColor: node.properties.backgroundColor.toFlutterColor (),
7086 elevation: node.properties.elevation,
71- automaticallyImplyLeading: node.properties.leading.icon.show
72- ? node.properties.automaticallyImplyLeading
73- : false ,
74- title: title,
7587 foregroundColor:
7688 node.properties.titleStyle.fills.firstOrNull? .toFlutterColor (),
77- titleSpacing: node.properties.titleSpacing,
7889 shadowColor: node.properties.shadowColor.toFlutterColor (),
7990 actions: [
8091 for (final item
8192 in node.properties.actions.whereType <IconAppBarActionItem >())
82- IconButton (
83- onPressed: () => onTriggerAction.call (context, item.reactions),
84- // splashRadius: 20,
85- iconSize: item.icon.size,
86- tooltip: item.tooltip,
93+ buildIconOrButton (
94+ context,
8795 icon: retrieveIconWidget (item.icon, item.icon.size) ??
8896 const SizedBox .shrink (),
97+ size: item.icon.size,
98+ tooltip: item.tooltip,
99+ reactions: item.reactions,
89100 ),
90101 ],
91102 );
92103 }
93104
105+ Widget buildIconOrButton (
106+ BuildContext context, {
107+ required Widget icon,
108+ required double ? size,
109+ required String ? tooltip,
110+ required List <Reaction > reactions,
111+ }) {
112+ final bool hasReactions = reactions
113+ .where (
114+ (reaction) => reaction.trigger.type == TriggerType .click,
115+ )
116+ .isNotEmpty;
117+ if (hasReactions) {
118+ return IconButton (
119+ onPressed: () => onTriggerAction.call (context, reactions),
120+ icon: icon,
121+ iconSize: size,
122+ tooltip: tooltip,
123+ );
124+ } else {
125+ return icon;
126+ }
127+ }
128+
94129 void onTriggerAction (BuildContext context, List <Reaction > reactions) async {
95130 final bool executed = await FunctionsRepository .triggerAction (
96131 context, reactions: reactions, TriggerType .click);
@@ -159,25 +194,45 @@ class PassiveAppBarWidget extends StatelessWidget
159194 final AppBarNode node;
160195 final double ? elevation;
161196 final WidgetBuildSettings settings;
162- final Function (BuildContext context, List <Reaction > reactions)?
163- onLeadingPressed;
164- final Function (BuildContext context, List <Reaction > reactions)?
165- onActionPressed;
197+ final TriggerAction ? onTriggerAction;
166198 final List <VariableData > variablesOverrides;
167199
168200 const PassiveAppBarWidget ({
169201 super .key,
170202 required this .node,
171203 required this .settings,
172204 this .elevation,
173- this .onLeadingPressed,
174- this .onActionPressed,
205+ this .onTriggerAction,
175206 this .variablesOverrides = const [],
176207 });
177208
178209 @override
179210 Size get preferredSize => node.outerBoxLocal.size.flutterSize;
180211
212+ Widget buildIconOrButton (
213+ BuildContext context, {
214+ required Widget icon,
215+ required double ? size,
216+ required String ? tooltip,
217+ required List <Reaction > reactions,
218+ }) {
219+ final bool hasReactions = reactions
220+ .where (
221+ (reaction) => reaction.trigger.type == TriggerType .click,
222+ )
223+ .isNotEmpty;
224+ if (hasReactions && onTriggerAction != null ) {
225+ return IconButton (
226+ onPressed: () => onTriggerAction! .call (context, reactions),
227+ icon: icon,
228+ iconSize: size,
229+ tooltip: tooltip,
230+ );
231+ } else {
232+ return icon;
233+ }
234+ }
235+
181236 @override
182237 Widget build (BuildContext context) {
183238 final Widget ? leading = node.properties.leading.icon.show &&
@@ -190,9 +245,7 @@ class PassiveAppBarWidget extends StatelessWidget
190245 : TextUtils .buildText (
191246 context,
192247 node.properties.title,
193- textAlignHorizontal: null ,
194- maxLines: null ,
195- overflow: null ,
248+ fontSize: node.properties.titleStyle.fontSize,
196249 node: node,
197250 variablesOverrides: variablesOverrides,
198251 nullSubstitutionMode: settings.nullSubstitutionMode,
@@ -201,18 +254,26 @@ class PassiveAppBarWidget extends StatelessWidget
201254 return AdaptiveNodeBox (
202255 node: node,
203256 child: AppBar (
257+ toolbarHeight: node.middleBoxLocal.height,
204258 centerTitle: node.properties.centerTitle,
259+ leadingWidth: node.properties.leading.icon.size,
205260 leading: leading != null
206- ? IconButton (
207- onPressed: () => onLeadingPressed? .call (
208- context, node.properties.leading.reactions),
209- icon: leading,
261+ ? Center (
262+ child: buildIconOrButton (
263+ context,
264+ icon: leading,
265+ size: node.properties.leading.icon.size,
266+ tooltip: node.properties.leading.tooltip,
267+ reactions: node.properties.leading.reactions,
268+ ),
210269 )
211270 : null ,
212271 titleTextStyle: TextUtils .retrieveTextStyleFromProp (
213272 node.properties.titleStyle,
214273 effects: const [],
215274 ),
275+ // TODO(Saad,Birju): Make surfaceTintColor a property of the AppBarNode.
276+ surfaceTintColor: node.properties.backgroundColor.toFlutterColor (),
216277 backgroundColor: node.properties.backgroundColor.toFlutterColor (),
217278 elevation: elevation ?? node.properties.elevation,
218279 automaticallyImplyLeading: node.properties.leading.icon.show
@@ -226,13 +287,13 @@ class PassiveAppBarWidget extends StatelessWidget
226287 actions: [
227288 for (final item
228289 in node.properties.actions.whereType <IconAppBarActionItem >())
229- IconButton (
230- onPressed: () => onActionPressed? .call (context, item.reactions),
231- // splashRadius: 20,
232- iconSize: item.icon.size,
233- tooltip: item.tooltip,
290+ buildIconOrButton (
291+ context,
234292 icon: retrieveIconWidget (item.icon, item.icon.size) ??
235293 const SizedBox .shrink (),
294+ size: item.icon.size,
295+ tooltip: item.tooltip,
296+ reactions: item.reactions,
236297 ),
237298 ],
238299 ),
0 commit comments