@@ -114,6 +114,7 @@ class Switch extends StatelessWidget {
114114 this .overlayColor,
115115 this .splashRadius,
116116 this .focusNode,
117+ this .onFocusChange,
117118 this .autofocus = false ,
118119 }) : _switchType = _SwitchType .material,
119120 assert (dragStartBehavior != null ),
@@ -158,6 +159,7 @@ class Switch extends StatelessWidget {
158159 this .overlayColor,
159160 this .splashRadius,
160161 this .focusNode,
162+ this .onFocusChange,
161163 this .autofocus = false ,
162164 }) : assert (autofocus != null ),
163165 assert (activeThumbImage != null || onActiveThumbImageError == null ),
@@ -455,6 +457,9 @@ class Switch extends StatelessWidget {
455457 /// {@macro flutter.widgets.Focus.focusNode}
456458 final FocusNode ? focusNode;
457459
460+ /// {@macro flutter.material.inkwell.onFocusChange}
461+ final ValueChanged <bool >? onFocusChange;
462+
458463 /// {@macro flutter.widgets.Focus.autofocus}
459464 final bool autofocus;
460465
@@ -478,6 +483,7 @@ class Switch extends StatelessWidget {
478483 final Size size = _getSwitchSize (context);
479484 return Focus (
480485 focusNode: focusNode,
486+ onFocusChange: onFocusChange,
481487 autofocus: autofocus,
482488 child: Container (
483489 width: size.width, // Same size as the Material switch.
@@ -518,6 +524,7 @@ class Switch extends StatelessWidget {
518524 overlayColor: overlayColor,
519525 splashRadius: splashRadius,
520526 focusNode: focusNode,
527+ onFocusChange: onFocusChange,
521528 autofocus: autofocus,
522529 );
523530 }
@@ -577,6 +584,7 @@ class _MaterialSwitch extends StatefulWidget {
577584 this .overlayColor,
578585 this .splashRadius,
579586 this .focusNode,
587+ this .onFocusChange,
580588 this .autofocus = false ,
581589 }) : assert (dragStartBehavior != null ),
582590 assert (activeThumbImage != null || onActiveThumbImageError == null ),
@@ -603,6 +611,7 @@ class _MaterialSwitch extends StatefulWidget {
603611 final MaterialStateProperty <Color ?>? overlayColor;
604612 final double ? splashRadius;
605613 final FocusNode ? focusNode;
614+ final Function (bool )? onFocusChange;
606615 final bool autofocus;
607616 final Size size;
608617
@@ -822,6 +831,7 @@ class _MaterialSwitchState extends State<_MaterialSwitch> with TickerProviderSta
822831 child: buildToggleable (
823832 mouseCursor: effectiveMouseCursor,
824833 focusNode: widget.focusNode,
834+ onFocusChange: widget.onFocusChange,
825835 autofocus: widget.autofocus,
826836 size: widget.size,
827837 painter: _painter
0 commit comments