BaseSwitch class

BaseSwitch - Cross-platform switch with native iOS support

Uses CNSwitch (Cupertino Native) for iOS - provides true native iOS appearance with built-in liquid glass effects and native rendering. Uses Material Switch for Android and other platforms.

*** use cupertino = { forceUseMaterial: true } force use Material Switch on iOS *** use material = { forceUseCupertino: true } force use CNSwitch on Android

Features:

  • Native iOS switch via CNSwitch (cupertino_native package)
  • Material Design switch for Android
  • Consistent API across platforms
  • Built-in liquid glass effects on iOS (no manual wrapper needed)

Example:

BaseSwitch(
  value: _switchValue,
  onChanged: (v) => setState(() => _switchValue = v),
  activeColor: Colors.pink,
)

Updated: 2024.10.25 - Integrated CNSwitch for native iOS rendering

Inheritance

Constructors

BaseSwitch({Key? key, bool? value, ValueChanged<bool>? onChanged, Color? activeColor, Color? cupertinoTrackColor, MaterialStateProperty<Color?>? materialTrackColor, DragStartBehavior dragStartBehavior = DragStartBehavior.start, Color? activeTrackColor, Color? inactiveThumbColor, Color? inactiveTrackColor, ImageProvider<Object>? activeThumbImage, ImageErrorListener? onActiveThumbImageError, ImageProvider<Object>? inactiveThumbImage, ImageErrorListener? onInactiveThumbImageError, MaterialTapTargetSize? materialTapTargetSize, MouseCursor? mouseCursor, Color? focusColor, Color? hoverColor, FocusNode? focusNode, MaterialStateProperty<Color?>? overlayColor, double? splashRadius, MaterialStateProperty<Color?>? thumbColor, bool autofocus = false, BaseParam? baseParam})
const

Properties

activeColor → Color?
CupertinoSwitch.activeColor or Switch.activeColor
final
activeThumbImage → ImageProvider<Object>?
Switch.activeThumbImage
final
activeTrackColor → Color?
*** cupertino properties end *** *** material properties start *** Switch.activeTrackColor
final
autofocus → bool
Switch.autofocus
final
baseParam → BaseParam?
Personalization parameters, gets platform parameters first, then mode parameters
finalinherited
cupertinoTrackColor → Color?
*** gerenal properties end *** *** cupertino properties start *** CupertinoSwitch.trackColor
final
dragStartBehavior → DragStartBehavior
CupertinoSwitch.dragStartBehavior or Switch.dragStartBehavior
final
focusColor → Color?
Switch.focusColor
final
focusNode → FocusNode?
Switch.focusNode
final
hashCode → int
The hash code for this object.
no setterinherited
hoverColor → Color?
Switch.hoverColor
final
inactiveThumbColor → Color?
Switch.inactiveThumbColor
final
inactiveThumbImage → ImageProvider<Object>?
Switch.inactiveThumbImage
final
inactiveTrackColor → Color?
Switch.inactiveTrackColor
final
key → Key?
Controls how one widget replaces another widget in the tree.
finalinherited
materialTapTargetSize → MaterialTapTargetSize?
Switch.materialTapTargetSize
final
materialTrackColor → MaterialStateProperty<Color?>?
final
mouseCursor → MouseCursor?
Switch.mouseCursor
final
onActiveThumbImageError → ImageErrorListener?
Switch.onActiveThumbImageError
final
onChanged → ValueChanged<bool>?
CupertinoSwitch.onChanged or Switch.onChanged
final
onInactiveThumbImageError → ImageErrorListener?
Switch.onInactiveThumbImageError
final
overlayColor → MaterialStateProperty<Color?>?
Switch.overlayColor
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
splashRadius → double?
Switch.splashRadius
final
thumbColor → MaterialStateProperty<Color?>?
Switch.thumbColor
final
value → bool?
*** gerenal properties start *** CupertinoSwitch.value or Switch.value
final

Methods

beforeBuild(BuildContext context) → void
Called before build
inherited
beforeBuildByCupertino(BuildContext context) → void
Called before buildByCupertino
inherited
beforeBuildByCupertinoNative(BuildContext context) → void
Called before buildByCupertinoNative (native iOS implementation)
inherited
beforeBuildByMaterial(BuildContext context) → void
Called before buildByMaterial
inherited
build(BuildContext context) → Widget
Describes the part of the user interface represented by this widget.
inherited
buildByCupertino(BuildContext context) → Widget
*** material properties end ***
buildByCupertinoNative(BuildContext context) → dynamic
build on cupertino mode with native iOS components (cupertino_native package) This is called when baseParam.nativeIOS = true Default implementation falls back to buildByCupertino()
inherited
buildByMaterial(BuildContext context) → Widget
build on material mode
commonBuild(BuildContext context, BaseParam? baseParam) → dynamic
inherited
createElement() → StatelessElement
Creates a StatelessElement to manage this widget's location in the tree.
inherited
debugDescribeChildren() → List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
getBuildMode(BaseParam? baseParam) → WidgetBuildMode
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) → String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String
Returns a one-line detailed description of the object.
inherited
toStringShort() → String
A short, textual description of this widget.
inherited
valueOf(String key, dynamic value) → dynamic
inherited
valueOfBaseParam(BaseParam? baseParam, String key, dynamic value) → dynamic
No reflection available in Dart First get value from platform, then from mode, finally from value itself
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited