The DynamicShapeStyle
type allows you to define two distinct styles for a shape—one for light mode and another for dark mode. The system automatically applies the appropriate style based on the current color scheme (light or dark) of the user’s device.
Dynamic styling is a critical aspect of creating adaptive and visually appealing user interfaces. With DynamicShapeStyle
, you can ensure that your shapes blend seamlessly with the user's preferred color scheme by defining separate styles for light and dark modes.
Key points:
light
property.dark
property.light: ShapeStyle
The style to apply when the system is in light mode.
dark: ShapeStyle
The style to apply when the system is in dark mode.
ShapeStyle
The ShapeStyle
can be a color, gradient, or material. For example:
"red"
, hex values like "#FF0000"
, or CSS-like RGBA strings like "rgba(255, 0, 0, 1)"
."regularMaterial"
, "thickMaterial"
.In this example, the shape appears blue in light mode and gray in dark mode.
Here, the shape uses a light blue to white gradient in light mode and a dark blue to black gradient in dark mode.
This configuration applies a regular material in light mode and an ultra-thick material in dark mode.
DynamicShapeStyle
?Dynamic styling helps create a better user experience by ensuring:
With DynamicShapeStyle
, you can create flexible and adaptive styles for shapes that seamlessly respond to the user's color scheme. By defining separate styles for light and dark modes, your app will look great in any environment, ensuring a consistent and user-friendly experience.