Skip to content

ehtsham623/dynamic_theme_nullsafe

Repository files navigation

dynamic_theme_nullsafe

Dynamically changing your theme without hassle

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

Include in your project

dependencies:
  dynamic_theme_nullsafe: ^1.0.5

run packages get and import it

import 'package:dynamic_theme_nullsafe/dynamic_theme_nullsafe.dart';

Usage

Wrap your material app like this:

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return DynamicThemeNullsafe(
      defaultThemeMode: ThemeMode.light,
      loadThemeOnStart: true,
      data: (mode) => ThemeData(
        primarySwatch: Colors.indigo,
        brightness: mode == ThemeMode.dark ? Brightness.dark : Brightness.light,
      ),
      themedWidgetBuilder: (
        BuildContext context,
        ThemeMode mode,
        ThemeData? data,
      ) {
        return MaterialApp(
          themeMode: mode,
          title: 'Flutter Demo',
          theme: data,
          home: const MyHomePage(title: 'Flutter Demo Home Page'),
        );
      },
    );
  }
}

Change the theme like this:

  void changeBrightness() {
    DynamicThemeNullsafe.of(context).toggleThemeMode();
  }

  void changeColor() {
    DynamicThemeNullsafe.of(context).setThemeMode(ThemeMode.dark);
  }

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

Getting Started

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

For help on editing package code, view the documentation.

About

Flutter Dart package on Pub.dev for using dark and light themes. Created from existed outdated package and modified for null safety.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors