dynamic_themes
1.1.0, released 6 years ago by julianassmann.de
Dynamically switch between multiple themes and persist selection across restarts.
What it does
It lets you define a collection of ThemeData objects, choose one at runtime, and automatically saves the chosen theme ID using shared_preferences. The selected theme is restored when the app restarts.
AI-written summary of version 1.1.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need a user-selectable theme system that survives app restarts
- You want a simple, widget-based API without extra state management
Skip it when
- You already use a complex state management solution that handles theme persistence
- You need advanced theming features like dynamic color schemes or platform adaptive theming
Strengths
- Easy to set up with a single widget
- Persisted theme selection via shared_preferences
- Supports any number of themes
- No external code generation required
Weaknesses
- Relies on shared_preferences, so limited to key-value storage
- No support for dynamic color schemes or system theme sync
- Only works with Flutter MaterialApp
Setup
- Kind
- Flutter widgets
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 1
Add dependency, wrap MaterialApp with DynamicTheme, provide ThemeCollection and optional defaultThemeId
final themeCollection = ThemeCollection(
themes: {
0: ThemeData(primarySwatch: Colors.blue),
1: ThemeData(primarySwatch: Colors.red),
2: ThemeData.dark(),
},
fallbackTheme: ThemeData.light(),
);
return DynamicTheme(
themeCollection: themeCollection,
defaultThemeId: 0,
builder: (context, theme) => MaterialApp(
theme: theme,
home: HomePage(),
),
);Alternatives
Packages that do the same job and could replace dynamic_themes.
- xdg_icons
XDG theme icons for Flutter.
62Compare - random_color_scheme
Generates random light and dark Material Design color schemes respecting WCAG guidelines.
57Compare - derived_colors
Generate color variants and modifications for Flutter applications.
50Compare - theme_provider
Easy to use and customizable Theme Provider with persistence and dynamic switching.
50Compare
Works with
Packages commonly used together with dynamic_themes: ones it builds on, ones built on it, and its own family.