https://github.com/Norbert515/dynamic_theme
Dynamically changing your theme without hassle
https://github.com/Norbert515/dynamic_theme
Last synced: about 1 year ago
JSON representation
Dynamically changing your theme without hassle
- Host: GitHub
- URL: https://github.com/Norbert515/dynamic_theme
- Owner: Norbert515
- License: mit
- Created: 2018-05-31T13:06:16.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2021-12-20T10:11:54.000Z (over 4 years ago)
- Last Synced: 2025-03-28T18:17:35.731Z (about 1 year ago)
- Language: Dart
- Homepage:
- Size: 189 KB
- Stars: 322
- Watchers: 9
- Forks: 67
- Open Issues: 31
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](https://proandroiddev.com/how-to-dynamically-change-the-theme-in-flutter-698bd022d0f0)!
## 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:
```dart
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:
```dart
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](https://flutter.io/).
For help on editing package code, view the [documentation](https://flutter.io/developing-packages/).