Ci-dessous une mise en œuvre simple:
class AdaptiveSwitch extends StatelessWidget {
const AdaptiveSwitch({Key key,
@required this.value,
@required this.onChanged,
this.activeColor,
this.dragStartBehavior = DragStartBehavior.start})
: assert(dragStartBehavior != null),
super(key: key);
final bool value;
final ValueChanged<bool> onChanged;
final Color activeColor;
final DragStartBehavior dragStartBehavior;
@override
Widget build(BuildContext context) {
return Theme.of(context).targetPlatform = TargetPlatform.iOS
? CupertinoSwitch(
value: value,
activeColor: activeColor,
onChanged: onChanged,
dragStartBehavior: dragStartBehavior,
)
: Switch(
value: value,
activeColor: activeColor,
onChanged: onChanged,
dragStartBehavior: dragStartBehavior,
);
}
}