adaptive_theme
3.8.0, released 3 months ago by birju.dev
Dynamic light and dark theme switching with persistence for Flutter.
What it does
Allows apps to dynamically switch between light, dark, and system-default themes. Persists theme choices across app restarts using shared_preferences and provides listeners for theme changes.
AI-written summary of version 3.8.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need to support manual light and dark theme switching in your app.
- You want theme mode changes to persist automatically across app restarts.
- You want to support system-adaptive theme changes easily.
Skip it when
- You only need a static theme defined once without any runtime switching or persistence.
- You are using a complex custom state management setup where you prefer handling theme state manually.
Strengths
- Persists theme mode automatically across app restarts.
- Supports both Material (MaterialApp) and Cupertino (CupertinoApp) apps.
- Includes a debug floating theme button for quick testing.
- Provides ValueNotifier to easily listen to theme changes.
Weaknesses
- Does not persist full custom theme data changes, only the theme mode (light/dark/system).
- Requires wrapping the app root widget.
Setup
- Kind
- Flutter widgets
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 3
Wrap your MaterialApp or CupertinoApp with AdaptiveTheme or CupertinoAdaptiveTheme.
AdaptiveTheme(
light: ThemeData.light(useMaterial3: true),
dark: ThemeData.dark(useMaterial3: true),
initial: AdaptiveThemeMode.light,
builder: (theme, darkTheme) => MaterialApp(
title: 'Adaptive Theme Demo',
theme: theme,
darkTheme: darkTheme,
home: MyHomePage(),
),
)Alternatives
Packages that do the same job and could replace adaptive_theme.
- flex_color_scheme
Choose this if you need advanced custom Material color schemes and extensive pre-built themes rather than just light/dark toggling.
89Compare
Works with
Packages commonly used together with adaptive_theme: ones it builds on, ones built on it, and its own family.
- shared_preferencesadaptive_theme depends on itFlutter plugin for reading and writing simple key-value pairs. Wraps NSUserDefaults on iOS and SharedPreferences on Android.
- material_uiadaptive_theme depends on itOfficial Flutter Material UI library implementing Google’s Material Design system.
- cupertino_uiadaptive_theme depends on itOfficial Flutter Cupertino design library implementing Apple HIG iOS and macOS user interfaces.