Flutter animation example
Flutter Animated Toggle Switch: Day and Night
A dark mode switch is a chance for a little delight. Flip this toggle and the sun rolls across the track, turning into a moon with craters as it goes, while the sky changes from blue with clouds to night with twinkling stars. The knob stretches slightly mid-travel, which makes the motion feel springy.
- 4.2 KB file
- 4 live inputs
- Flutter runtime
How this day night toggle works
- Knob position is a spring; its width grows with speed, a small squash-and-stretch touch.
- Sun and moon are the same circle, and a crescent mask slides in as progress passes halfway.
- The "dark" input sets the state and "toggle" fires on every change.
Add it to your Flutter app
Install exodeui_flutter, download the file below, and paste this. The code updates as you customize. Other runtimes are in the other tabs.
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:exodeui_flutter/exodeui_flutter.dart';
// Add assets/flutter-toggle-switch.exode to pubspec.yaml (download it below).
class FlutterToggleSwitch extends StatefulWidget {
const FlutterToggleSwitch({super.key});
@override
State<FlutterToggleSwitch> createState() => _FlutterToggleSwitchState();
}
class _FlutterToggleSwitchState extends State<FlutterToggleSwitch> {
final _canvas = GlobalKey<ExodeUICanvasState>();
late final Future<String> _json = rootBundle.loadString('assets/flutter-toggle-switch.exode');
@override
Widget build(BuildContext context) {
return FutureBuilder<String>(
future: _json,
builder: (context, snap) => snap.hasData
? ExodeUICanvas(
key: _canvas,
artboardJson: snap.data!,
fit: 'Layout',
onReady: () { },
onTrigger: (name, _) {
// fires: 'toggle'
},
)
: const SizedBox.shrink(),
);
}
}Inputs
| Input | Type | Default | Range |
|---|---|---|---|
dark | Boolean | false | — |
accent | Text | #38bdf8 | hex colour |
accent2 | Text | #1e1b4b | hex colour |
bg | Text | #0b1020 | hex colour |
Events: toggle
More Flutter animations
Bouncing Bars LoaderFive bars bouncing in a travelling wave with squash and stretch, plus rotating status messages.Speed Dial FABA floating action button that rotates to close while three labelled actions spring out in sequence.Hero Product TransitionA list item whose image arcs into the detail header while a circular reveal uncovers the page.3D Drawer MenuA side menu revealed by the page swinging back in 3D; open by tapping or dragging from the edge.Wavy TypewriterA typewriter whose letters drop in with a bounce; words type, hold, delete and cycle.Parallax Scroll ListA scrolling list of cards whose images shift at a slower rate, with momentum and edge bounce.