Skip to content
On this page

Switch

A binary control with an animated thumb and theme-aware colors.

Switch in FluttyUISwitch in FluttyUI dark theme

Import

import 'package:flutter/widgets.dart';
import 'package:fluttyui/fluttyui.dart' as ui;

Usage

Use this expression inside a stateful widget. Keep the current value in your widget state and update it in the callback.

ui.Switch(
  value: enabled,
  onChanged: (value) => setState(() => enabled = value),
)

API Reference

The declarations below match the current FluttyUI source. Types are shown without the optional ui. import prefix.

Switch

const Switch({
  super.key,
  this.motion,
  required this.value,
  required this.onChanged,
  this.enabled = true,
  this.size,
  this.width,
  this.height,
  this.thumbSize,
  this.thumbWidth,
  this.activeColor,
  this.inactiveColor,
  this.thumbColor = const Color(0xFFFFFFFF),
  this.borderColor = const Color(0x00000000),
  this.thumbPadding,
});
ParameterTypeRequiredDefault
keyKey?Nonull
motionComponentMotion?Nonull
valueboolYes—
onChangedValueChanged<bool>?Yes—
enabledboolNotrue
sizeComponentSize?Nonull
widthdouble?Nonull
heightdouble?Nonull
thumbSizedouble?Nonull
thumbWidthdouble?Nonull
activeColorColor?Nonull
inactiveColorColor?Nonull
thumbColorColorNoconst Color(0xFFFFFFFF)
borderColorColorNoconst Color(0x00000000)
thumbPaddingdouble?Nonull

Application Setup

Place components under FluttyApp to provide theme, navigation, localization, and overlay defaults. Use theme tokens for shared appearance settings.

Source

lib/src/widgets/controls/switch/switch.dart

This reference is generated from the Switch declaration in the FluttyUI core checkout. The component catalog lists the other available building blocks.

DartFlutter

Get started with FluttyUI