11import 'package:flutter/material.dart' ;
22
33import '../models/control.dart' ;
4+ import '../utils/colors.dart' ;
45import '../utils/edge_insets.dart' ;
56import '../utils/launch_url.dart' ;
67import 'create_control.dart' ;
8+ import 'cupertino_list_tile.dart' ;
79import 'flet_control_stateless_mixin.dart' ;
10+ import 'flet_store_mixin.dart' ;
811
912class ListTileClicks extends InheritedWidget {
1013 const ListTileClicks ({
@@ -23,7 +26,8 @@ class ListTileClicks extends InheritedWidget {
2326 bool updateShouldNotify (ListTileClicks oldWidget) => true ;
2427}
2528
26- class ListTileControl extends StatelessWidget with FletControlStatelessMixin {
29+ class ListTileControl extends StatelessWidget
30+ with FletControlStatelessMixin , FletStoreMixin {
2731 final Control ? parent;
2832 final Control control;
2933 final List <Control > children;
@@ -40,76 +44,93 @@ class ListTileControl extends StatelessWidget with FletControlStatelessMixin {
4044 @override
4145 Widget build (BuildContext context) {
4246 debugPrint ("ListTile build: ${control .id }" );
43-
44- var leadingCtrls =
45- children.where ((c) => c.name == "leading" && c.isVisible);
46- var titleCtrls = children.where ((c) => c.name == "title" && c.isVisible);
47- var subtitleCtrls =
48- children.where ((c) => c.name == "subtitle" && c.isVisible);
49- var trailingCtrls =
50- children.where ((c) => c.name == "trailing" && c.isVisible);
51-
52- bool selected = control.attrBool ("selected" , false )! ;
53- bool dense = control.attrBool ("dense" , false )! ;
54- bool isThreeLine = control.attrBool ("isThreeLine" , false )! ;
55- bool autofocus = control.attrBool ("autofocus" , false )! ;
56- bool onclick = control.attrBool ("onclick" , false )! ;
57- bool toggleInputs = control.attrBool ("toggleInputs" , false )! ;
58- bool onLongPressDefined = control.attrBool ("onLongPress" , false )! ;
59- String url = control.attrString ("url" , "" )! ;
60- String ? urlTarget = control.attrString ("urlTarget" );
61- bool disabled = control.isDisabled || parentDisabled;
62-
63- Function ()? onPressed = (onclick || toggleInputs || url != "" ) && ! disabled
64- ? () {
65- debugPrint ("ListTile ${control .id } clicked!" );
66- if (toggleInputs) {
67- _clickNotifier.onClick ();
68- }
69- if (url != "" ) {
70- openWebBrowser (url, webWindowName: urlTarget);
71- }
72- if (onclick) {
73- sendControlEvent (context, control.id, "click" , "" );
47+ return withPagePlatform ((context, platform) {
48+ bool adaptive = control.attrBool ("adaptive" , false )! ;
49+ if (adaptive &&
50+ (platform == TargetPlatform .iOS ||
51+ platform == TargetPlatform .macOS)) {
52+ return CupertinoListTileControl (
53+ control: control,
54+ parent: parent,
55+ parentDisabled: parentDisabled,
56+ children: children);
57+ }
58+
59+ var leadingCtrls =
60+ children.where ((c) => c.name == "leading" && c.isVisible);
61+ var titleCtrls = children.where ((c) => c.name == "title" && c.isVisible);
62+ var subtitleCtrls =
63+ children.where ((c) => c.name == "subtitle" && c.isVisible);
64+ var trailingCtrls =
65+ children.where ((c) => c.name == "trailing" && c.isVisible);
66+
67+ bool selected = control.attrBool ("selected" , false )! ;
68+ bool dense = control.attrBool ("dense" , false )! ;
69+ bool isThreeLine = control.attrBool ("isThreeLine" , false )! ;
70+ bool autofocus = control.attrBool ("autofocus" , false )! ;
71+ bool onclick = control.attrBool ("onclick" , false )! ;
72+ bool toggleInputs = control.attrBool ("toggleInputs" , false )! ;
73+ bool onLongPressDefined = control.attrBool ("onLongPress" , false )! ;
74+ String url = control.attrString ("url" , "" )! ;
75+ String ? urlTarget = control.attrString ("urlTarget" );
76+ bool disabled = control.isDisabled || parentDisabled;
77+
78+ Function ()? onPressed =
79+ (onclick || toggleInputs || url != "" ) && ! disabled
80+ ? () {
81+ debugPrint ("ListTile ${control .id } clicked!" );
82+ if (toggleInputs) {
83+ _clickNotifier.onClick ();
84+ }
85+ if (url != "" ) {
86+ openWebBrowser (url, webWindowName: urlTarget);
87+ }
88+ if (onclick) {
89+ sendControlEvent (context, control.id, "click" , "" );
90+ }
91+ }
92+ : null ;
93+
94+ Function ()? onLongPress = onLongPressDefined && ! disabled
95+ ? () {
96+ debugPrint ("Button ${control .id } clicked!" );
97+ sendControlEvent (context, control.id, "long_press" , "" );
7498 }
75- }
76- : null ;
77-
78- Function ()? onLongPress = onLongPressDefined && ! disabled
79- ? () {
80- debugPrint ("Button ${control .id } clicked!" );
81- sendControlEvent (context, control.id, "long_press" , "" );
82- }
83- : null ;
84-
85- Widget tile = ListTile (
86- autofocus: autofocus,
87- contentPadding: parseEdgeInsets (control, "contentPadding" ),
88- isThreeLine: isThreeLine,
89- selected: selected,
90- dense: dense,
91- onTap: onPressed,
92- onLongPress: onLongPress,
93- enabled: ! disabled,
94- leading: leadingCtrls.isNotEmpty
95- ? createControl (control, leadingCtrls.first.id, disabled)
96- : null ,
97- title: titleCtrls.isNotEmpty
98- ? createControl (control, titleCtrls.first.id, disabled)
99- : null ,
100- subtitle: subtitleCtrls.isNotEmpty
101- ? createControl (control, subtitleCtrls.first.id, disabled)
102- : null ,
103- trailing: trailingCtrls.isNotEmpty
104- ? createControl (control, trailingCtrls.first.id, disabled)
105- : null ,
106- );
107-
108- if (toggleInputs) {
109- tile = ListTileClicks (notifier: _clickNotifier, child: tile);
110- }
111-
112- return constrainedControl (context, tile, parent, control);
99+ : null ;
100+
101+ Widget tile = ListTile (
102+ autofocus: autofocus,
103+ contentPadding: parseEdgeInsets (control, "contentPadding" ),
104+ isThreeLine: isThreeLine,
105+ selected: selected,
106+ dense: dense,
107+ onTap: onPressed,
108+ onLongPress: onLongPress,
109+ enabled: ! disabled,
110+ tileColor: HexColor .fromString (
111+ Theme .of (context), control.attrString ("bgcolor" , "" )! ),
112+ splashColor: HexColor .fromString (
113+ Theme .of (context), control.attrString ("bgcolorActivated" , "" )! ),
114+ leading: leadingCtrls.isNotEmpty
115+ ? createControl (control, leadingCtrls.first.id, disabled)
116+ : null ,
117+ title: titleCtrls.isNotEmpty
118+ ? createControl (control, titleCtrls.first.id, disabled)
119+ : null ,
120+ subtitle: subtitleCtrls.isNotEmpty
121+ ? createControl (control, subtitleCtrls.first.id, disabled)
122+ : null ,
123+ trailing: trailingCtrls.isNotEmpty
124+ ? createControl (control, trailingCtrls.first.id, disabled)
125+ : null ,
126+ );
127+
128+ if (toggleInputs) {
129+ tile = ListTileClicks (notifier: _clickNotifier, child: tile);
130+ }
131+
132+ return constrainedControl (context, tile, parent, control);
133+ });
113134 }
114135}
115136
0 commit comments