@@ -114,6 +114,7 @@ class Switch extends StatelessWidget {
114
114
this .overlayColor,
115
115
this .splashRadius,
116
116
this .focusNode,
117
+ this .onFocusChange,
117
118
this .autofocus = false ,
118
119
}) : _switchType = _SwitchType .material,
119
120
assert (dragStartBehavior != null ),
@@ -158,6 +159,7 @@ class Switch extends StatelessWidget {
158
159
this .overlayColor,
159
160
this .splashRadius,
160
161
this .focusNode,
162
+ this .onFocusChange,
161
163
this .autofocus = false ,
162
164
}) : assert (autofocus != null ),
163
165
assert (activeThumbImage != null || onActiveThumbImageError == null ),
@@ -455,6 +457,9 @@ class Switch extends StatelessWidget {
455
457
/// {@macro flutter.widgets.Focus.focusNode}
456
458
final FocusNode ? focusNode;
457
459
460
+ /// {@macro flutter.material.inkwell.onFocusChange}
461
+ final ValueChanged <bool >? onFocusChange;
462
+
458
463
/// {@macro flutter.widgets.Focus.autofocus}
459
464
final bool autofocus;
460
465
@@ -478,6 +483,7 @@ class Switch extends StatelessWidget {
478
483
final Size size = _getSwitchSize (context);
479
484
return Focus (
480
485
focusNode: focusNode,
486
+ onFocusChange: onFocusChange,
481
487
autofocus: autofocus,
482
488
child: Container (
483
489
width: size.width, // Same size as the Material switch.
@@ -518,6 +524,7 @@ class Switch extends StatelessWidget {
518
524
overlayColor: overlayColor,
519
525
splashRadius: splashRadius,
520
526
focusNode: focusNode,
527
+ onFocusChange: onFocusChange,
521
528
autofocus: autofocus,
522
529
);
523
530
}
@@ -577,6 +584,7 @@ class _MaterialSwitch extends StatefulWidget {
577
584
this .overlayColor,
578
585
this .splashRadius,
579
586
this .focusNode,
587
+ this .onFocusChange,
580
588
this .autofocus = false ,
581
589
}) : assert (dragStartBehavior != null ),
582
590
assert (activeThumbImage != null || onActiveThumbImageError == null ),
@@ -603,6 +611,7 @@ class _MaterialSwitch extends StatefulWidget {
603
611
final MaterialStateProperty <Color ?>? overlayColor;
604
612
final double ? splashRadius;
605
613
final FocusNode ? focusNode;
614
+ final Function (bool )? onFocusChange;
606
615
final bool autofocus;
607
616
final Size size;
608
617
@@ -822,6 +831,7 @@ class _MaterialSwitchState extends State<_MaterialSwitch> with TickerProviderSta
822
831
child: buildToggleable (
823
832
mouseCursor: effectiveMouseCursor,
824
833
focusNode: widget.focusNode,
834
+ onFocusChange: widget.onFocusChange,
825
835
autofocus: widget.autofocus,
826
836
size: widget.size,
827
837
painter: _painter
0 commit comments