@@ -34,7 +34,11 @@ class EnsembleTripleSwitch extends SwitchBase {
34
34
Map <String , Function > setters () => Map <String , Function >.from (super .setters ())
35
35
..addAll ({
36
36
'value' : (value) => _controller.value =
37
- SwitchState .values.from (value)? .name ?? SwitchState .off.name
37
+ SwitchState .values.from (value)? .name ?? SwitchState .off.name,
38
+ 'custom' : (value) =>
39
+ _controller.custom = Utils .getBool (value, fallback: false ),
40
+ 'height' : (value) => _controller.height = Utils .optionalDouble (value),
41
+ 'width' : (value) => _controller.width = Utils .optionalDouble (value),
38
42
});
39
43
40
44
void onToggle (SwitchState newValue) {
@@ -158,14 +162,23 @@ class SwitchBaseState extends FormFieldWidgetState<SwitchBase> {
158
162
startBackgroundColor: widget._controller.activeColor,
159
163
middleBackgroundColor: widget._controller.mixedColor,
160
164
endBackgroundColor: widget._controller.inactiveColor,
165
+ width: widget._controller.width,
166
+ height: widget._controller.height,
161
167
disable: widget._controller.enabled == false ,
162
168
state: switchState,
163
169
onChanged: isEnabled ()
164
170
? (value) {
165
- (widget as EnsembleTripleSwitch ? )? .onToggle (value);
166
- onChange ();
171
+ if (! widget._controller.custom) {
172
+ (widget as EnsembleTripleSwitch ? )? .onToggle (value);
173
+ }
174
+ onChange (value.name);
167
175
}
168
176
: (_) {},
177
+ onThumbTapped: (value) {
178
+ if (widget._controller.custom) {
179
+ onChange (value.name);
180
+ }
181
+ },
169
182
);
170
183
}
171
184
@@ -202,20 +215,25 @@ class SwitchBaseState extends FormFieldWidgetState<SwitchBase> {
202
215
onChanged: isEnabled ()
203
216
? (value) {
204
217
(widget as EnsembleSwitch ? )? .onToggle (value);
205
- onChange ();
218
+ onChange (value );
206
219
}
207
220
: null );
208
221
}
209
222
210
- void onChange () {
223
+ void onChange (dynamic value ) {
211
224
if (widget._controller.onChange != null ) {
212
225
ScreenController ().executeAction (context, widget._controller.onChange! ,
213
- event: EnsembleEvent (widget));
226
+ event: EnsembleEvent (widget,
227
+ data:
228
+ (widget._controller.custom && widget is EnsembleTripleSwitch )
229
+ ? {'value' : value}
230
+ : null ));
214
231
}
215
232
}
216
233
}
217
234
218
235
class SwitchBaseController extends FormFieldController {
236
+ bool custom = false ;
219
237
dynamic value;
220
238
String ? leadingText;
221
239
String ? trailingText;
@@ -224,6 +242,8 @@ class SwitchBaseController extends FormFieldController {
224
242
Color ? inactiveColor;
225
243
Color ? inactiveThumbColor;
226
244
Color ? mixedColor;
245
+ double ? width = 100 ;
246
+ double ? height = 40 ;
227
247
228
248
framework.EnsembleAction ? onChange;
229
249
}
@@ -248,6 +268,7 @@ class TripleStateSwitch extends StatelessWidget {
248
268
Key ? key,
249
269
required this .onChanged,
250
270
required this .state,
271
+ this .onThumbTapped,
251
272
this .startBackgroundColor,
252
273
this .middleBackgroundColor,
253
274
this .endBackgroundColor,
@@ -262,6 +283,7 @@ class TripleStateSwitch extends StatelessWidget {
262
283
}) : super (key: key);
263
284
264
285
final Function (SwitchState ) onChanged;
286
+ final Function (SwitchState )? onThumbTapped;
265
287
final double ? width;
266
288
final double ? height;
267
289
final BorderRadius ? borderRadius;
@@ -343,26 +365,29 @@ class TripleStateSwitch extends StatelessWidget {
343
365
: state == SwitchState .mixed
344
366
? AlignmentDirectional .center
345
367
: AlignmentDirectional .centerEnd,
346
- child: child ??
347
- Container (
348
- height: height,
349
- width: height,
350
- decoration: BoxDecoration (
351
- shape: BoxShape .circle,
352
- color: ! disable!
353
- ? dotColor ?? SwitchColors .dotColor
354
- : SwitchColors .disableDotColor,
355
- boxShadow: ! disable!
356
- ? [
357
- const BoxShadow (
358
- color: Colors .black,
359
- blurRadius: 10 ,
360
- spreadRadius: - 5 ,
361
- ),
362
- ]
363
- : null ,
368
+ child: InkWell (
369
+ onTap: () => onThumbTapped? .call (state),
370
+ child: child ??
371
+ Container (
372
+ height: height,
373
+ width: height,
374
+ decoration: BoxDecoration (
375
+ shape: BoxShape .circle,
376
+ color: ! disable!
377
+ ? dotColor ?? SwitchColors .dotColor
378
+ : SwitchColors .disableDotColor,
379
+ boxShadow: ! disable!
380
+ ? [
381
+ const BoxShadow (
382
+ color: Colors .black,
383
+ blurRadius: 10 ,
384
+ spreadRadius: - 5 ,
385
+ ),
386
+ ]
387
+ : null ,
388
+ ),
364
389
),
365
- ),
390
+ ),
366
391
),
367
392
],
368
393
),
0 commit comments