Flutter Theme Orchestrator
A powerful Flutter theme management system with support for dynamic colors, theme scheduling, transitions, and persistence.
Preview
Features
- π¨ Dynamic Colors Support: Seamlessly integrate with Material You/Dynamic Colors
- π Theme Scheduling: Schedule theme changes based on time or events
- π Smooth Transitions: Beautiful animations when switching between themes
- πΎ Theme Persistence: Save and restore theme preferences
- π― Type-safe: Fully typed API for better development experience
- π± Platform Support: Works on Android, iOS, Web, Desktop
Getting Started
Add the package to your pubspec.yaml:
dependencies:
flutter_theme_orchestrator: ^0.1.1
Usage
Basic Setup
import 'package:flutter_theme_orchestrator/flutter_theme_orchestrator.dart';
void main() {
runApp(
ThemeOrchestrator(
child: MyApp(),
initialTheme: ThemeData.light(),
),
);
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeOrchestrator.of(context).currentTheme,
darkTheme: ThemeOrchestrator.of(context).darkTheme,
themeMode: ThemeOrchestrator.of(context).themeMode,
home: MyHomePage(),
);
}
}
Dynamic Theme Switching
// Switch theme with smooth transition
ThemeOrchestrator.of(context).setTheme(ThemeData.dark());
// Toggle between light and dark
ThemeOrchestrator.of(context).toggleTheme();
// With custom transition duration
ThemeOrchestrator.of(context).setTheme(
ThemeData.dark(),
duration: Duration(milliseconds: 500),
);
Theme Scheduling
// Schedule dark theme from 8 PM to 6 AM
ThemeOrchestrator.of(context).scheduleTheme(
ThemeSchedule(
startTime: TimeOfDay(hour: 20, minute: 0),
endTime: TimeOfDay(hour: 6, minute: 0),
theme: ThemeData.dark(),
),
);
// Schedule multiple themes
ThemeOrchestrator.of(context).scheduleThemes([
ThemeSchedule(
startTime: TimeOfDay(hour: 6, minute: 0),
endTime: TimeOfDay(hour: 17, minute: 0),
theme: ThemeData.light(),
),
ThemeSchedule(
startTime: TimeOfDay(hour: 17, minute: 0),
endTime: TimeOfDay(hour: 20, minute: 0),
theme: eveningTheme,
),
ThemeSchedule(
startTime: TimeOfDay(hour: 20, minute: 0),
endTime: TimeOfDay(hour: 6, minute: 0),
theme: ThemeData.dark(),
),
]);
Dynamic Colors
// Enable dynamic colors (Material You)
ThemeOrchestrator.of(context).setDynamicColorsEnabled(true);
// Create theme with dynamic colors
final theme = ThemeOrchestrator.of(context).createTheme(
primaryColor: Colors.blue,
useDynamicColors: true,
);
Theme Persistence
// Save current theme state
await ThemeOrchestrator.of(context).saveThemeState();
// Restore saved theme state
await ThemeOrchestrator.of(context).restoreThemeState();
// Custom storage implementation
class MyCustomStorage extends ThemeStorage {
@override
Future<ThemeState?> loadThemeState() async {
// Implement your loading logic
}
@override
Future<void> saveThemeState(ThemeState state) async {
// Implement your saving logic
}
}
// Use custom storage
ThemeOrchestrator(
storage: MyCustomStorage(),
child: MyApp(),
);
Example App
Check out the example folder for a complete demo app showcasing all features:
The example app demonstrates:
- Dynamic theme switching with animations
- Material You integration
- Theme scheduling
- Theme persistence
- Custom theme configurations
- Platform-specific adaptations
Advanced Usage
For detailed documentation and advanced usage examples, visit our Wiki.
Contributing
Contributions are welcome! Please read our contributing guidelines to get started.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Libraries
- flutter_theme_orchestrator
- A powerful Flutter theme management system with support for dynamic colors, theme scheduling, transitions, and persistence.
- main