1
+ import 'package:flet/src/controls/cupertino_button.dart' ;
1
2
import 'package:flutter/material.dart' ;
2
3
3
4
import '../models/control.dart' ;
@@ -8,6 +9,7 @@ import '../utils/launch_url.dart';
8
9
import 'create_control.dart' ;
9
10
import 'error.dart' ;
10
11
import 'flet_control_stateful_mixin.dart' ;
12
+ import 'flet_store_mixin.dart' ;
11
13
12
14
class ElevatedButtonControl extends StatefulWidget {
13
15
final Control ? parent;
@@ -27,7 +29,7 @@ class ElevatedButtonControl extends StatefulWidget {
27
29
}
28
30
29
31
class _ElevatedButtonControlState extends State <ElevatedButtonControl >
30
- with FletControlStatefulMixin {
32
+ with FletControlStatefulMixin , FletStoreMixin {
31
33
late final FocusNode _focusNode;
32
34
String ? _lastFocusValue;
33
35
@@ -54,103 +56,116 @@ class _ElevatedButtonControlState extends State<ElevatedButtonControl>
54
56
Widget build (BuildContext context) {
55
57
debugPrint ("Button build: ${widget .control .id }" );
56
58
57
- String text = widget.control.attrString ("text" , "" )! ;
58
- String url = widget.control.attrString ("url" , "" )! ;
59
- IconData ? icon = parseIcon (widget.control.attrString ("icon" , "" )! );
60
- Color ? iconColor = HexColor .fromString (
61
- Theme .of (context), widget.control.attrString ("iconColor" , "" )! );
62
- var contentCtrls = widget.children.where ((c) => c.name == "content" );
63
- bool onHover = widget.control.attrBool ("onHover" , false )! ;
64
- bool onLongPress = widget.control.attrBool ("onLongPress" , false )! ;
65
- bool autofocus = widget.control.attrBool ("autofocus" , false )! ;
66
- bool disabled = widget.control.isDisabled || widget.parentDisabled;
67
-
68
- Function ()? onPressed = ! disabled
69
- ? () {
70
- debugPrint ("Button ${widget .control .id } clicked!" );
71
- if (url != "" ) {
72
- openWebBrowser (url,
73
- webWindowName: widget.control.attrString ("urlTarget" ));
59
+ return withPagePlatform ((context, platform) {
60
+ bool adaptive = widget.control.attrBool ("adaptive" , false )! ;
61
+ if (adaptive &&
62
+ (platform == TargetPlatform .iOS ||
63
+ platform == TargetPlatform .macOS)) {
64
+ return CupertinoButtonControl (
65
+ control: widget.control,
66
+ parentDisabled: widget.parentDisabled,
67
+ children: widget.children);
68
+ }
69
+
70
+ String text = widget.control.attrString ("text" , "" )! ;
71
+ String url = widget.control.attrString ("url" , "" )! ;
72
+ IconData ? icon = parseIcon (widget.control.attrString ("icon" , "" )! );
73
+ Color ? iconColor = HexColor .fromString (
74
+ Theme .of (context), widget.control.attrString ("iconColor" , "" )! );
75
+ var contentCtrls = widget.children.where ((c) => c.name == "content" );
76
+ bool onHover = widget.control.attrBool ("onHover" , false )! ;
77
+ bool onLongPress = widget.control.attrBool ("onLongPress" , false )! ;
78
+ bool autofocus = widget.control.attrBool ("autofocus" , false )! ;
79
+ bool disabled = widget.control.isDisabled || widget.parentDisabled;
80
+
81
+ Function ()? onPressed = ! disabled
82
+ ? () {
83
+ debugPrint ("Button ${widget .control .id } clicked!" );
84
+ if (url != "" ) {
85
+ openWebBrowser (url,
86
+ webWindowName: widget.control.attrString ("urlTarget" ));
87
+ }
88
+ sendControlEvent (widget.control.id, "click" , "" );
74
89
}
75
- sendControlEvent (widget.control.id, "click" , "" );
76
- }
77
- : null ;
78
-
79
- Function ()? onLongPressHandler = onLongPress && ! disabled
80
- ? () {
81
- debugPrint ("Button ${widget .control .id } long pressed!" );
82
- sendControlEvent (widget.control.id, "long_press" , "" );
83
- }
84
- : null ;
85
-
86
- Function (bool )? onHoverHandler = onHover && ! disabled
87
- ? (state) {
88
- debugPrint ("Button ${widget .control .id } hovered!" );
89
- sendControlEvent (widget.control.id, "hover" , state.toString ());
90
- }
91
- : null ;
92
-
93
- ElevatedButton ? button;
94
-
95
- var theme = Theme .of (context);
96
-
97
- var style = parseButtonStyle (Theme .of (context), widget.control, "style" ,
98
- defaultForegroundColor: theme.colorScheme.primary,
99
- defaultBackgroundColor: theme.colorScheme.surface,
100
- defaultOverlayColor: theme.colorScheme.primary.withOpacity (0.08 ),
101
- defaultShadowColor: theme.colorScheme.shadow,
102
- defaultSurfaceTintColor: theme.colorScheme.surfaceTint,
103
- defaultElevation: 1 ,
104
- defaultPadding: const EdgeInsets .symmetric (horizontal: 8 ),
105
- defaultBorderSide: BorderSide .none,
106
- defaultShape: theme.useMaterial3
107
- ? const StadiumBorder ()
108
- : RoundedRectangleBorder (borderRadius: BorderRadius .circular (4 )));
109
-
110
- if (icon != null ) {
111
- if (text == "" ) {
112
- return const ErrorControl ("Error displaying ElevatedButton" ,
113
- description: "\" icon\" must be specified together with \" text\" ." );
90
+ : null ;
91
+
92
+ Function ()? onLongPressHandler = onLongPress && ! disabled
93
+ ? () {
94
+ debugPrint ("Button ${widget .control .id } long pressed!" );
95
+ sendControlEvent (widget.control.id, "long_press" , "" );
96
+ }
97
+ : null ;
98
+
99
+ Function (bool )? onHoverHandler = onHover && ! disabled
100
+ ? (state) {
101
+ debugPrint ("Button ${widget .control .id } hovered!" );
102
+ sendControlEvent (widget.control.id, "hover" , state.toString ());
103
+ }
104
+ : null ;
105
+
106
+ ElevatedButton ? button;
107
+
108
+ var theme = Theme .of (context);
109
+
110
+ var style = parseButtonStyle (Theme .of (context), widget.control, "style" ,
111
+ defaultForegroundColor: theme.colorScheme.primary,
112
+ defaultBackgroundColor: theme.colorScheme.surface,
113
+ defaultOverlayColor: theme.colorScheme.primary.withOpacity (0.08 ),
114
+ defaultShadowColor: theme.colorScheme.shadow,
115
+ defaultSurfaceTintColor: theme.colorScheme.surfaceTint,
116
+ defaultElevation: 1 ,
117
+ defaultPadding: const EdgeInsets .symmetric (horizontal: 8 ),
118
+ defaultBorderSide: BorderSide .none,
119
+ defaultShape: theme.useMaterial3
120
+ ? const StadiumBorder ()
121
+ : RoundedRectangleBorder (borderRadius: BorderRadius .circular (4 )));
122
+
123
+ if (icon != null ) {
124
+ if (text == "" ) {
125
+ return const ErrorControl ("Error displaying ElevatedButton" ,
126
+ description:
127
+ "\" icon\" must be specified together with \" text\" ." );
128
+ }
129
+ button = ElevatedButton .icon (
130
+ style: style,
131
+ autofocus: autofocus,
132
+ focusNode: _focusNode,
133
+ onPressed: onPressed,
134
+ onLongPress: onLongPressHandler,
135
+ onHover: onHoverHandler,
136
+ icon: Icon (
137
+ icon,
138
+ color: iconColor,
139
+ ),
140
+ label: Text (text));
141
+ } else if (contentCtrls.isNotEmpty) {
142
+ button = ElevatedButton (
143
+ style: style,
144
+ autofocus: autofocus,
145
+ focusNode: _focusNode,
146
+ onPressed: onPressed,
147
+ onLongPress: onLongPressHandler,
148
+ onHover: onHoverHandler,
149
+ child:
150
+ createControl (widget.control, contentCtrls.first.id, disabled));
151
+ } else {
152
+ button = ElevatedButton (
153
+ style: style,
154
+ autofocus: autofocus,
155
+ focusNode: _focusNode,
156
+ onPressed: onPressed,
157
+ onLongPress: onLongPressHandler,
158
+ onHover: onHoverHandler,
159
+ child: Text (text));
160
+ }
161
+
162
+ var focusValue = widget.control.attrString ("focus" );
163
+ if (focusValue != null && focusValue != _lastFocusValue) {
164
+ _lastFocusValue = focusValue;
165
+ _focusNode.requestFocus ();
114
166
}
115
- button = ElevatedButton .icon (
116
- style: style,
117
- autofocus: autofocus,
118
- focusNode: _focusNode,
119
- onPressed: onPressed,
120
- onLongPress: onLongPressHandler,
121
- onHover: onHoverHandler,
122
- icon: Icon (
123
- icon,
124
- color: iconColor,
125
- ),
126
- label: Text (text));
127
- } else if (contentCtrls.isNotEmpty) {
128
- button = ElevatedButton (
129
- style: style,
130
- autofocus: autofocus,
131
- focusNode: _focusNode,
132
- onPressed: onPressed,
133
- onLongPress: onLongPressHandler,
134
- onHover: onHoverHandler,
135
- child:
136
- createControl (widget.control, contentCtrls.first.id, disabled));
137
- } else {
138
- button = ElevatedButton (
139
- style: style,
140
- autofocus: autofocus,
141
- focusNode: _focusNode,
142
- onPressed: onPressed,
143
- onLongPress: onLongPressHandler,
144
- onHover: onHoverHandler,
145
- child: Text (text));
146
- }
147
-
148
- var focusValue = widget.control.attrString ("focus" );
149
- if (focusValue != null && focusValue != _lastFocusValue) {
150
- _lastFocusValue = focusValue;
151
- _focusNode.requestFocus ();
152
- }
153
-
154
- return constrainedControl (context, button, widget.parent, widget.control);
167
+
168
+ return constrainedControl (context, button, widget.parent, widget.control);
169
+ });
155
170
}
156
171
}
0 commit comments