simple_theme_switcher 0.0.7 copy "simple_theme_switcher: ^0.0.7" to clipboard
simple_theme_switcher: ^0.0.7 copied to clipboard

Simple light/dark mode switcher using material theme.Just wrap your App with STMaterialApp Widget and toggle it with a switch.

Simple Theme Switcher #

A lightweight Flutter package for easily switching between light and dark themes with minimal setup. This package simplifies theme management, allowing developers to toggle themes efficiently.


Features #

  • Simple and intuitive theme management.
  • Toggle between light and dark themes.
  • Minimal configuration required.

Installation #

Add simple_theme_switcher to your pubspec.yaml:

dependencies:
  simple_theme_switcher: ^latest

Run the following command:

flutter pub get

Usage #

Step 1: Wrap Your App with STMaterialApp #

In your main.dart file, replace MaterialApp with STMaterialApp:

import 'package:flutter/material.dart';
import 'package:simple_theme_switcher/simple_theme_switcher.dart';

void main() {
  runApp(const STMaterialApp(child: MyApp()));
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const HomeScreen();
  }
}

class HomeScreen extends StatelessWidget {
  const HomeScreen({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.primaryContainer,
        title: Text(
          'Theme Switcher Example',
          style: TextStyle(
            color: Theme.of(context).colorScheme.onPrimaryContainer,
          ),
        ),
      ),
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            final themeManager = ThemeManager();
            themeManager.toggleTheme(
              themeManager.currentThemeMode == AppThemeMode.light
                  ? AppThemeMode.dark
                  : AppThemeMode.light,
              seedColor: Colors.yellow, // Optional seed color
            );
          },
          child: const Text('Toggle Theme'),
        ),
      ),
    );
  }
}

Important Notes #

  • Do not use both MaterialApp and STMaterialApp simultaneously. This will cause conflicts.
  • Simply replace MaterialApp with STMaterialApp and pass any required parameters.

API #

STMaterialApp #

A widget that manages theme switching.

const STMaterialApp({required Widget child});

ThemeManager #

Singleton class for managing themes.

  • currentThemeMode — Returns the current AppThemeMode (light or dark).
  • toggleTheme(AppThemeMode themeMode, {Color? seedColor}) — Switches the theme to the specified mode. An optional seedColor parameter can be provided.

Example #

A full working example is available in the example/ directory.


License #

This project is licensed under the MIT License.

1
likes
160
points
157
downloads

Publisher

unverified uploader

Weekly Downloads

Simple light/dark mode switcher using material theme.Just wrap your App with STMaterialApp Widget and toggle it with a switch.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, flutter_bloc

More

Packages that depend on simple_theme_switcher