DsThemeToggle class
A single-button theme toggle that cycles through Light → Dark → System.
Each press advances to the next ThemeMode:
Light (☀) → Dark (☽) → System (⬡) → Light …
The icon swaps with a rotate + scale + fade animation so the transition feels smooth ("스르륵"). All colors come from Theme.of(context).colorScheme — nothing is hardcoded.
───────────────────────────────────────────── Usage (minimal — caller owns the state) ─────────────────────────────────────────────
class _RootState extends State<Root> {
ThemeMode _mode = ThemeMode.system;
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: BrandATheme.light(),
darkTheme: BrandATheme.dark(),
themeMode: _mode,
home: Scaffold(
appBar: AppBar(
actions: [
DsThemeToggle(
themeMode: _mode,
onChanged: (m) => setState(() => _mode = m),
),
const SizedBox(width: 8),
],
),
),
);
}
}
───────────────────────────────────────────── Usage with a ValueNotifier (no StatefulWidget needed) ─────────────────────────────────────────────
final themeMode = ValueNotifier(ThemeMode.system);
// In build:
ValueListenableBuilder<ThemeMode>(
valueListenable: themeMode,
builder: (_, mode, __) => DsThemeToggle(
themeMode: mode,
onChanged: (m) => themeMode.value = m,
),
)
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatelessWidget
- DsThemeToggle
Constructors
-
DsThemeToggle({Key? key, required ThemeMode themeMode, required ValueChanged<
ThemeMode> onChanged, double sizedBoxDimension = 48, double iconSize = 22}) -
const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- iconSize → double
-
The size of the icon. Defaults to 22.
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
-
onChanged
→ ValueChanged<
ThemeMode> -
Called with the next ThemeMode when the user taps the button.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- sizedBoxDimension → double
-
The size of the square tap target. Defaults to 48.
final
- themeMode → ThemeMode
-
The currently active theme mode.
final
Methods
-
build(
BuildContext context) → Widget -
Describes the part of the user interface represented by this widget.
override
-
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
-
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
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited