Last updated:
0 purchases
flutter theme 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(),
),
),
);
}
}
copied to clipboard
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(),
),
),
copied to clipboard
Parameters of ThemeProvider() #
Example with all parameters
ThemeProvider(defaultThemeName: "Light", themes: [
{"Light": ThemeData.light()},
{"Dark": ThemeData.dark()}
])),
copied to clipboard
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
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.