Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fluttercommunity/persist_theme
Persist Theme - A flutter plugin for persisting the theme data. Support for Dark Modes. Maintainer @rodydavis
https://github.com/fluttercommunity/persist_theme
dark-theme flutter material-design persist-theme theme
Last synced: 3 months ago
JSON representation
Persist Theme - A flutter plugin for persisting the theme data. Support for Dark Modes. Maintainer @rodydavis
- Host: GitHub
- URL: https://github.com/fluttercommunity/persist_theme
- Owner: fluttercommunity
- License: mit
- Created: 2019-05-24T18:19:06.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-09-27T18:18:32.000Z (over 3 years ago)
- Last Synced: 2024-10-12T14:30:05.390Z (4 months ago)
- Topics: dark-theme, flutter, material-design, persist-theme, theme
- Language: Dart
- Homepage: https://fluttercommunity.github.io/persist_theme/
- Size: 4.81 MB
- Stars: 69
- Watchers: 4
- Forks: 12
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[![Flutter Community: persist_theme](https://fluttercommunity.dev/_github/header/persist_theme)](https://github.com/fluttercommunity/community)
[![Buy Me A Coffee](https://img.shields.io/badge/Donate-Buy%20Me%20A%20Coffee-yellow.svg)](https://www.buymeacoffee.com/rodydavis)
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WSH3GVC49GNNJ)
![github pages](https://github.com/fluttercommunity/persist_theme/workflows/github%20pages/badge.svg)# persist_theme
A Flutter plugin for persisting and dynamically changing the theme.
Online Demo: https://fluttercommunity.github.io/persist_theme/
``` dart
import 'package:flutter/material.dart';import 'package:persist_theme/persist_theme.dart';
import 'package:provider/provider.dart';
import 'package:scoped_model/scoped_model.dart';import 'dart:io' show Platform;
import 'package:flutter/foundation.dart';/// main is entry point of Flutter application
void main() {
// Desktop platforms aren't a valid platform.
_setTargetPlatformForDesktop();return runApp(MyApp());
}/// If the current platform is desktop, override the default platform to
/// a supported platform (iOS for macOS, Android for Linux and Windows).
/// Otherwise, do nothing.
void _setTargetPlatformForDesktop() {
TargetPlatform targetPlatform;
if (Platform.isMacOS) {
targetPlatform = TargetPlatform.iOS;
} else if (Platform.isLinux || Platform.isWindows) {
targetPlatform = TargetPlatform.android;
}
if (targetPlatform != null) {
debugDefaultTargetPlatformOverride = targetPlatform;
}
}final _model = ThemeModel();
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ListenableProvider(
create: (_) => _model..init(),
child: Consumer(
builder: (context, model, child) {
return MaterialApp(
theme: model.theme,
home: HomeScreen(),
);
},
),
);
}
}class HomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
final _theme = Provider.of(context);
return Scaffold(
appBar: AppBar(
title: const Text('Persist Theme'),
),
body: ListView(
children: MediaQuery.of(context).size.width >= 480
? [
Flex(
direction: Axis.horizontal,
children: [
Flexible(child: DarkModeSwitch()),
Flexible(child: TrueBlackSwitch()),
],
),
CustomThemeSwitch(),
Flex(
direction: Axis.horizontal,
children: [
Flexible(child: PrimaryColorPicker()),
Flexible(child: AccentColorPicker()),
],
),
DarkAccentColorPicker(),
]
: [
DarkModeSwitch(),
TrueBlackSwitch(),
CustomThemeSwitch(),
PrimaryColorPicker(),
AccentColorPicker(),
DarkAccentColorPicker(),
],
),
floatingActionButton: FloatingActionButton(
backgroundColor: _theme.accentColor,
child: Icon(Icons.add),
onPressed: () {},
),
);
}
}```
## Customization
* There are widgets provided but can be fully customized.
* By default hide elements based on the theme.
* The only requirement is that the material app is wrapped in a scoped model like shown above.## Screenshots