Search categories, packages and repositories

Package detailsv1.0.1

dynamic_theme

Changes the theme during runtime, also presists brightness settings across restarts

30-day downloads
875
Likes
136
Pub points
40

Install package

flutter pub add dynamic_theme

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

Dynamic Theme is a Flutter package that enables runtime theme switching, allowing users to toggle between light and dark modes seamlessly. It automatically persists brightness settings across app restarts, ensuring a consistent user experience. The package integrates easily with MaterialApp and provides simple APIs to update themes dynamically. Ideal for apps aiming to offer customizable appearance options without requiring a full rebuild.

Use cases

  • Runtime theme switching
  • Preserving user preferences after restart
  • Supporting dark mode in mobile apps
  • Customizing UI appearance on the fly
  • Enhancing accessibility with theme flexibility

Key features

  • Real-time theme updates
  • Automatic brightness persistence
  • Simple integration with MaterialApp
  • Light and dark mode support
  • Minimal boilerplate code

Suitable for

  • Apps needing dynamic theming
  • Developers prioritizing user experience
  • Projects supporting dark mode
  • Cross-platform mobile applications
  • Apps with customizable UI

Considerations

  • Limited to brightness and theme changes
  • No support for custom theme types beyond built-in
  • Requires manual handling of theme-specific assets
  • Not suitable for complex theme systems
  • Depends on MaterialApp for full functionality

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

dynamic_theme

Dynamically changing your theme without hassle

This packages manages changing your theme during runtime and persiting that theme.

I wrote a medium post about this, check it out here!

Include in your project

dependencies:
  dynamic_theme: ^1.0.1

run packages get and import it

import 'package:dynamic_theme/dynamic_theme.dart';

if you want the dialog:

import 'package:dynamic_theme/theme_switcher_widgets.dart';

Usage

Wrap your material app like this:


class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new DynamicTheme(
      defaultBrightness: Brightness.light,
      data: (brightness) => new ThemeData(
        primarySwatch: Colors.indigo,
        brightness: brightness,
      ),
      themedWidgetBuilder: (context, theme) {
        return new MaterialApp(
          title: 'Flutter Demo',
          theme: theme,
          home: new MyHomePage(title: 'Flutter Demo Home Page'),
        );
      }
    );
  }
}

Change the theme like this:

  void changeBrightness() {
    DynamicTheme.of(context).setBrightness(Theme.of(context).brightness == Brightness.dark? Brightness.light: Brightness.dark);
  }
  
  void changeColor() {
    DynamicTheme.of(context).setThemeData(new ThemeData(
        primaryColor: Theme.of(context).primaryColor == Colors.indigo? Colors.red: Colors.indigo
    ));
  }

When changing the brightness with setBrightness, it is additionally stored in the shared preferences.

Also included

A dialog widget to change the brightness!

Getting Started

For help getting started with Flutter, view our online documentation.

For help on editing package code, view the documentation.

Categories

Dependencies

Dependency list 1 items

Source repository

Projects using this package

No data available yet.