Here’s the complete README.md in Markdown for your Flutter Theme Manager package:

markdown Copy code

Flutter Theme Manager

A lightweight and flexible package for managing dynamic themes in Flutter applications. The package supports light and dark themes, theme persistence, and real-time theme updates with an easy-to-use API.


Features

  • 🌓 Dynamic Theme Switching: Easily switch between light and dark themes.
  • 💾 Theme Persistence: Automatically saves and restores the user's preferred theme.
  • 🚀 Real-time Updates: Notify the app of theme changes with minimal setup.
  • 🎨 Predefined Themes: Comes with customizable light and dark theme templates.

Getting Started

To use the package, add the following to your pubspec.yaml file:

dependencies:
  flutter_theme_manager: ^1.0.0

Usage

Usage

  1. Import the Package dart Copy code import 'package:flutter_theme_manager/flutter_theme_manager.dart';
  2. Initialize the ThemeManager Create an instance of ThemeManager in your app:

dart Copy code final ThemeManager themeManager = ThemeManager(); 3. Apply the Current Theme Wrap your MaterialApp with AnimatedBuilder to dynamically update the theme:

dart Copy code class MyApp extends StatelessWidget { final ThemeManager themeManager = ThemeManager();

@override Widget build(BuildContext context) { return AnimatedBuilder( animation: themeManager, builder: (context, _) { return MaterialApp( theme: themeManager.currentTheme, home: HomePage(themeManager: themeManager), ); }, ); } } 4. Toggle Themes You can toggle between light and dark themes using:

dart Copy code themeManager.toggleTheme(); 5. Example Here’s a complete example:

dart Copy code import 'package:flutter/material.dart'; import 'package:flutter_theme_manager/flutter_theme_manager.dart';

void main() { runApp(MyApp()); }

class MyApp extends StatelessWidget { final ThemeManager themeManager = ThemeManager();

@override Widget build(BuildContext context) { return AnimatedBuilder( animation: themeManager, builder: (context, _) { return MaterialApp( theme: themeManager.currentTheme, home: HomePage(themeManager: themeManager), ); }, ); } }

class HomePage extends StatelessWidget { final ThemeManager themeManager;

const HomePage({required this.themeManager});

@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Flutter Theme Manager'), ), body: Center( child: ElevatedButton( onPressed: themeManager.toggleTheme, child: Text('Toggle Theme'), ), ), ); } } API Documentation ThemeManager Class The core class for managing themes.

Properties currentTheme: Gets the current active theme (either light or dark). Methods toggleTheme(): Toggles between light and dark themes. Example Usage dart Copy code ThemeManager themeManager = ThemeManager(); themeManager.toggleTheme(); ThemeStorage Class Handles the persistence of the theme preference.

Methods saveThemeMode(bool isDarkMode): Saves the user's theme preference. getThemeMode(): Retrieves the saved theme preference.