ThemeBrightnessAnimatedBuilder class
A simple way to animate between light/dark themes with the animation tied to MaterialApp's ThemeData.
Tweens a double when the app changes from light theme to dark theme and lerps colors inline
Useful when an app is not using Material terminology/semantics for things like colors and typography.
Sample usage:
class MyLightAndDarkThemeWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ThemeBrightnessAnimatedBuilder(
builder: (context, t, child) {
final lightThemeColor = Colors.red.shade800;
final darkThemeColor = Colors.red.shade200;
return Container(
/// Light theme color goes on the right, dark theme on the left.
color: Color.lerp(lightThemeColor, darkThemeColor, t),
);
},
);
}
}
This widget was created by Luke Pighetti and edited by GroovinChip. Please view the original source here
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatelessWidget
- ThemeBrightnessAnimatedBuilder
Constructors
- ThemeBrightnessAnimatedBuilder({Key? key, required Widget builder(BuildContext, double, Widget?), Widget? child})
-
A builder that automatically transitions t between
0.0
and1.0
depending on if ThemeData.brightness is Brightness.dark or Brightness.lightconst
Properties
- builder → Widget Function(BuildContext, double, Widget?)
-
0.0
when ThemeData.brightness is Brightness.light1.0
when ThemeData.brightness is Brightness.darkfinal - child → Widget?
-
A child to pass through without rebuilding when animating.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
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}) → 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