xSWitch method

Widget xSWitch (
  1. {bool value,
  2. Color activeColor,
  3. Color activeTrackColor,
  4. Color inactiveThumbColor,
  5. Color inactiveTrackColor,
  6. ImageProvider<Object> activeThumbImage,
  7. ImageProvider<Object> inactiveThumbImage,
  8. MaterialTapTargetSize materialTapTargetSize,
  9. DragStartBehavior dragStartBehavior,
  10. Color focusColor,
  11. Color hoverColor,
  12. FocusNode focusNode,
  13. bool autofocus = false,
  14. Key key}
)

Called when the user toggles the switch on or off.

The switch passes the new value to the callback but does not actually change state until the parent widget rebuilds the switch with the new value.

If null, the switch will be displayed as disabled.

The callback provided to onChanged should update the state of the parent StatefulWidget using the State.setState method, so that the parent gets rebuilt; for example:

Switch(
  value: _giveVerse,
  onChanged: (bool newValue) {
    setState(() {
      _giveVerse = newValue;
    });
  },
)

Implementation

Widget xSWitch({
  /// Whether this switch is on or off.
  ///
  /// This property must not be null.
  final bool value,

  /// The color to use when this switch is on.
  ///
  /// Defaults to [ThemeData.toggleableActiveColor].
  final Color activeColor,

  /// The color to use on the track when this switch is on.
  ///
  /// Defaults to [ThemeData.toggleableActiveColor] with the opacity set at 50%.
  ///
  /// Ignored if this switch is created with [Switch.adaptive].
  final Color activeTrackColor,

  /// The color to use on the thumb when this switch is off.
  ///
  /// Defaults to the colors described in the Material design specification.
  ///
  /// Ignored if this switch is created with [Switch.adaptive].
  final Color inactiveThumbColor,

  /// The color to use on the track when this switch is off.
  ///
  /// Defaults to the colors described in the Material design specification.
  ///
  /// Ignored if this switch is created with [Switch.adaptive].
  final Color inactiveTrackColor,

  /// An image to use on the thumb of this switch when the switch is on.
  ///
  /// Ignored if this switch is created with [Switch.adaptive].
  final ImageProvider activeThumbImage,

  /// An image to use on the thumb of this switch when the switch is off.
  ///
  /// Ignored if this switch is created with [Switch.adaptive].
  final ImageProvider inactiveThumbImage,

  /// Configures the minimum size of the tap target.
  ///
  /// Defaults to [ThemeData.materialTapTargetSize].
  ///
  /// See also:
  ///
  ///  * [MaterialTapTargetSize], for a description of how this affects tap targets.
  final MaterialTapTargetSize materialTapTargetSize,

  /// {@macro flutter.cupertino.switch.dragStartBehavior}
  final DragStartBehavior dragStartBehavior,

  /// The color for the button's [Material] when it has the input focus.
  final Color focusColor,

  /// The color for the button's [Material] when a pointer is hovering over it.
  final Color hoverColor,

  /// {@macro flutter.widgets.Focus.focusNode}
  final FocusNode focusNode,

  /// {@macro flutter.widgets.Focus.autofocus}
  bool autofocus = false,
  final Key key,
}) {
  return Switch(
    value: value,
    onChanged: this,
    autofocus: autofocus,
    dragStartBehavior: dragStartBehavior,
    focusColor: focusColor,
    focusNode: focusNode,
    hoverColor: hoverColor,
    inactiveThumbColor: inactiveThumbColor,
    inactiveThumbImage: inactiveThumbImage,
    inactiveTrackColor: inactiveTrackColor,
    key: key,
    materialTapTargetSize: materialTapTargetSize,
    activeThumbImage: activeThumbImage,
    activeTrackColor: Colors.lightGreenAccent,
    activeColor: Colors.green,
  );
}