widget method
Implementation
widget(context) {
if (cupertino) {
Size _getSwitchSize(ThemeData theme) {
final MaterialTapTargetSize effectiveMaterialTapTargetSize =
materialTapTargetSize ??
theme.switchTheme.materialTapTargetSize ??
theme.materialTapTargetSize;
switch (effectiveMaterialTapTargetSize) {
case MaterialTapTargetSize.padded:
return const Size(_kSwitchWidth, _kSwitchHeight);
case MaterialTapTargetSize.shrinkWrap:
return const Size(_kSwitchWidth, _kSwitchHeightCollapsed);
}
}
return Builder(builder: (context) {
final Size size = _getSwitchSize(Theme.of(context));
return Focus(
focusNode: focusNode,
autofocus: autofocus ?? false,
child: Container(
width: size.width, // Same size as the Material switch.
height: size.height,
alignment: Alignment.center,
child: CupertinoSwitch(
dragStartBehavior: dragStartBehavior ?? DragStartBehavior.start,
value: value ?? false,
onChanged: onChanged,
activeColor: activeColor,
trackColor: inactiveTrackColor,
thumbColor: thumbColorState?.base,
),
),
);
});
}
if (adaptive)
return Switch.adaptive(
value: value ?? false,
onChanged: onChanged ?? null,
activeColor: activeColor,
activeTrackColor: activeTrackColor,
inactiveThumbColor: inactiveThumbColor,
inactiveTrackColor: inactiveTrackColor,
activeThumbImage: activeThumbImage,
onActiveThumbImageError: onActiveThumbImageError,
inactiveThumbImage: inactiveThumbImage,
onInactiveThumbImageError: onInactiveThumbImageError,
thumbColor: thumbColorState?.value,
trackColor: trackColorState?.value,
materialTapTargetSize: materialTapTargetSize,
dragStartBehavior: dragStartBehavior ?? DragStartBehavior.start,
mouseCursor: mouseCursor,
focusColor: focusColor,
hoverColor: hoverColor,
overlayColor: overlayColorState?.value,
splashRadius: splashRadius,
focusNode: focusNode,
autofocus: autofocus ?? false,
thumbIcon: thumbIconState?.value,
);
return Switch(
value: value ?? false,
onChanged: onChanged ?? null,
activeColor: activeColor,
activeTrackColor: activeTrackColor,
inactiveThumbColor: inactiveThumbColor,
inactiveTrackColor: inactiveTrackColor,
activeThumbImage: activeThumbImage,
onActiveThumbImageError: onActiveThumbImageError,
inactiveThumbImage: inactiveThumbImage,
onInactiveThumbImageError: onInactiveThumbImageError,
thumbColor: thumbColorState?.value,
trackColor: trackColorState?.value,
materialTapTargetSize: materialTapTargetSize,
dragStartBehavior: dragStartBehavior ?? DragStartBehavior.start,
mouseCursor: mouseCursor,
focusColor: focusColor,
hoverColor: hoverColor,
overlayColor: overlayColorState?.value,
splashRadius: splashRadius,
focusNode: focusNode,
autofocus: autofocus ?? false,
thumbIcon: thumbIconState?.value,
);
}