flutter_theme_orchestrator 0.1.0
flutter_theme_orchestrator: ^0.1.0 copied to clipboard
A powerful Flutter theme management system with support for dynamic colors, theme scheduling, transitions, and persistence.
Flutter Theme Orchestrator #
A powerful and flexible theme management system for Flutter applications that provides advanced features like theme scheduling, transitions, persistence, and Material 3 dynamic colors support.
Features #
- 🎨 Dynamic Color Support: Automatically adapts to system colors on supported platforms (Android 12+)
- 🔄 Theme Transitions: Smooth animated transitions between themes
- 💾 Theme Persistence: Save and restore theme preferences across app restarts
- ⏰ Theme Scheduling: Schedule theme changes based on time
- 🎯 Multiple Storage Options: Choose between SharedPreferences or in-memory storage
- 📱 Material 3 Support: Full support for Material 3 design system
- 🔧 Customizable: Extensive theme customization options
Installation #
Add this to your package's pubspec.yaml file:
dependencies:
flutter_theme_orchestrator: ^0.1.0
Usage #
Basic Setup #
Wrap your MaterialApp with ThemeOrchestrator:
import 'package:flutter_theme_orchestrator/flutter_theme_orchestrator.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ThemeOrchestrator(
storage: SharedPrefsThemeStorage(), // Optional: for theme persistence
initialThemeState: ThemeState.defaultLight(),
builder: (context, theme) {
return MaterialApp(
theme: theme,
home: MyHomePage(),
);
},
);
}
}
Changing Themes #
You can change themes anywhere in your app using the ThemeOrchestrator:
// Toggle between light and dark mode
ThemeOrchestrator.of(context).toggleThemeMode();
// Set a specific theme state
final newThemeState = ThemeState(
themeMode: ThemeMode.light,
primaryColor: Colors.blue,
useMaterial3: true,
);
ThemeOrchestrator.of(context).setThemeState(newThemeState);
// Schedule a theme change
final futureTime = DateTime.now().add(Duration(hours: 1));
ThemeOrchestrator.of(context).scheduleThemeChange(
ThemeState.defaultDark(),
futureTime,
);
Custom Theme Storage #
Implement your own storage solution by extending the ThemeStorage class:
class MyCustomStorage extends ThemeStorage {
@override
Future<ThemeState?> loadThemeState() async {
// Implement your loading logic
}
@override
Future<void> saveThemeState(ThemeState state) async {
// Implement your saving logic
}
@override
Future<void> clearThemeState() async {
// Implement your clearing logic
}
}
Advanced Features #
Dynamic Colors #
The package automatically handles Material You dynamic colors on supported platforms:
ThemeOrchestrator(
enableDynamicColors: true, // Enabled by default
builder: (context, theme) {
return MaterialApp(
theme: theme,
home: MyHomePage(),
);
},
);
Theme Transitions #
Customize theme transition animations:
ThemeOrchestrator(
transitionDuration: Duration(milliseconds: 500),
builder: (context, theme) {
return MaterialApp(
theme: theme,
home: MyHomePage(),
);
},
);
Custom Theme Properties #
Add custom properties to your theme state:
final themeState = ThemeState(
themeMode: ThemeMode.light,
primaryColor: Colors.blue,
customProperties: {
'customSpacing': 8.0,
'borderRadius': 4.0,
},
);
Contributing #
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
License #
This project is licensed under the MIT License - see the LICENSE file for details.