flutter_theme_provider 0.0.4 copy "flutter_theme_provider: ^0.0.4" to clipboard
flutter_theme_provider: ^0.0.4 copied to clipboard

A simple theme chenging plugin for flutter made top of provider

A theme changing package for flutter created on provider package

Features #

  • Provides a super simple way to provide theme for your flutter app.
  • Will save and apply your user's last theme they had set.
  • You can provide your own custom ThemeData

Getting started #

Just install a package it gives you the ability to change theme on the fly.

Usage #

Provide the ThemeProvider() class by a ChangeNotifierProvider to your MaterialApp

Usage: Just use theme: theme.getTheme() in your material app's theme parameter. () Don't forget to wrap material app with a Consumer<ThemeProvider>

to /example folder.

Example:

At your MaterialApp()

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        ChangeNotifierProvider(
            create: (context) =>
                ThemeProvider(defaultThemeName: "Light", themes: [
                  {"Light": ThemeData.light()},
                  {"Dark": ThemeData.dark()}
                ])),
      ],
      child: Consumer<ThemeProvider>(
        builder: (context, theme, child) => MaterialApp(
          home: ThemeChangeScreen(),
          theme: theme.getTheme(),
        ),
      ),
    );
  }
}

Where you want to provide theme changing option

        Consumer<ThemeProvider>(
          builder: (context, theme, child) => PopupMenuButton<dynamic>(
            offset: Offset(100, 0),
            child: ListTile(
              leading: const Icon(Icons.brush),
              title: const Text(
                "Theme",
                style: TextStyle(fontFamily: "Poppins"),
              ),
              subtitle: Text(
                "${theme.getThemeName()}",
                style: TextStyle(fontFamily: "Poppins"),
              ),
              trailing: Icon(Icons.edit),
            ),
            itemBuilder: (context) => theme.getThemeNames
                .map((item) => PopupMenuItem(
                      value: item,
                      child: Text(item),
                      onTap: () => theme.setTheme(item),
                    ))
                .toList(),
          ),
        ),

Parameters of ThemeProvider() #

Example with all parameters

    ThemeProvider(defaultThemeName: "Light", themes: [
        {"Light": ThemeData.light()},
        {"Dark": ThemeData.dark()}
    ])),

Parameter's description

String defaultThemeName required named

themes: List<Map<String, ThemeData>> Provide your theme data in a list of map, where key is the Theme Name and value is the theme data. (This name is used to reffer the themes)

Additional information #

If you want to contribute to the project please go to our github repo GitHub

4
likes
120
pub points
53%
popularity

Publisher

verified publisherniamulhasan.me

A simple theme chenging plugin for flutter made top of provider

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter, provider, shared_preferences

More

Packages that depend on flutter_theme_provider