persist_theme 1.5.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 94

Buy Me A Coffee Donate

persist_theme #

A Flutter plugin for persiting and dynamicly changing the theme.

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<ThemeModel>(
      builder: (_) => _model..init(),
      child: Consumer<ThemeModel>(
        builder: (context, model, child) {
          return MaterialApp(
            theme: model.theme,
            home: HomeScreen(),
          );
        },
      ),
    );
  }
}

class HomeScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final _theme = Provider.of<ThemeModel>(context);
    return Scaffold(
      appBar: AppBar(
        title: const Text('Persist Theme'),
      ),
      body: ListView(
        children: MediaQuery.of(context).size.width >= 480
            ? <Widget>[
                Flex(
                  direction: Axis.horizontal,
                  children: <Widget>[
                    Flexible(child: DarkModeSwitch()),
                    Flexible(child: TrueBlackSwitch()),
                  ],
                ),
                CustomThemeSwitch(),
                Flex(
                  direction: Axis.horizontal,
                  children: <Widget>[
                    Flexible(child: PrimaryColorPicker()),
                    Flexible(child: AccentColorPicker()),
                  ],
                ),
                DarkAccentColorPicker(),
              ]
            : <Widget>[
                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 #

Changelog #

1.5.1 #

  • Updating Provider

1.5.0 - [BREAKING CHANGE] - 05.24.2019

  • Fixing Color Bug
  • Switched to Provider
  • Updated Example
  • Added check for platform brightness

1.0.4 - 05.14.2019 #

  • Upgrading Dependencies

1.0.3 - 05.09.2019 #

  • Support for get darkTheme for System wide dark mode
  • Updated Example

1.0.2 - 05.04.2019 #

  • Support for Desktop

1.0.1 - 04.07.2019 #

  • Updated Example

1.0.0 - 04.07.2019 #

  • Breaking Changes: removed theme class in favor of localstorage plugin
  • Removed path_provider plugin
  • Updated some theme logic
  • Adding key if you want to save multiple themes
  • Changing readFromDisk to init
  • Added reset option

0.1.0 - 04.06.2019 #

  • Updating Example to be Desktop Aware

0.0.3 #

  • Adding Support for ThemeData overrides
  • Adding Default Theme
  • Updated Example

0.0.2 #

  • Fixing Analysis Issues

0.0.1 #

  • Created Plugin

example/README.md

persist_theme_example #

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<ThemeModel>(
      builder: (_) => _model..init(),
      child: Consumer<ThemeModel>(
        builder: (context, model, child) {
          return MaterialApp(
            theme: model.theme,
            home: HomeScreen(),
          );
        },
      ),
    );
  }
}

class HomeScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final _theme = Provider.of<ThemeModel>(context);
    return Scaffold(
      appBar: AppBar(
        title: const Text('Persist Theme'),
      ),
      body: ListView(
        children: MediaQuery.of(context).size.width >= 480
            ? <Widget>[
                Flex(
                  direction: Axis.horizontal,
                  children: <Widget>[
                    Flexible(child: DarkModeSwitch()),
                    Flexible(child: TrueBlackSwitch()),
                  ],
                ),
                CustomThemeSwitch(),
                Flex(
                  direction: Axis.horizontal,
                  children: <Widget>[
                    Flexible(child: PrimaryColorPicker()),
                    Flexible(child: AccentColorPicker()),
                  ],
                ),
                DarkAccentColorPicker(),
              ]
            : <Widget>[
                DarkModeSwitch(),
                TrueBlackSwitch(),
                CustomThemeSwitch(),
                PrimaryColorPicker(),
                AccentColorPicker(),
                DarkAccentColorPicker(),
              ],
      ),
      floatingActionButton: FloatingActionButton(
        backgroundColor: _theme.accentColor,
        child: Icon(Icons.add),
        onPressed: () {},
      ),
    );
  }
}


Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  persist_theme: ^1.5.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:persist_theme/persist_theme.dart';
  
Version Uploaded Documentation Archive
1.5.1 Jun 17, 2019 Go to the documentation of persist_theme 1.5.1 Download persist_theme 1.5.1 archive
1.5.0+1 May 24, 2019 Go to the documentation of persist_theme 1.5.0+1 Download persist_theme 1.5.0+1 archive
1.5.0 May 24, 2019 Go to the documentation of persist_theme 1.5.0 Download persist_theme 1.5.0 archive
1.0.4+1 May 24, 2019 Go to the documentation of persist_theme 1.0.4+1 Download persist_theme 1.0.4+1 archive
1.0.4 May 14, 2019 Go to the documentation of persist_theme 1.0.4 Download persist_theme 1.0.4 archive
1.0.3 May 9, 2019 Go to the documentation of persist_theme 1.0.3 Download persist_theme 1.0.3 archive
1.0.2 May 6, 2019 Go to the documentation of persist_theme 1.0.2 Download persist_theme 1.0.2 archive
1.0.1+1 Apr 8, 2019 Go to the documentation of persist_theme 1.0.1+1 Download persist_theme 1.0.1+1 archive
1.0.1 Apr 8, 2019 Go to the documentation of persist_theme 1.0.1 Download persist_theme 1.0.1 archive
1.0.0 Apr 8, 2019 Go to the documentation of persist_theme 1.0.0 Download persist_theme 1.0.0 archive

All 21 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
90
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
95
Overall:
Weighted score of the above. [more]
94
Learn more about scoring.

We analyzed this package on Jun 26, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.3.2
  • pana: 0.12.18
  • Flutter: 1.5.4-hotfix.2

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Fix lib/data/models/theme_model.dart. (-0.50 points)

Analysis of lib/data/models/theme_model.dart reported 1 hint:

line 3 col 8: Unused import: 'package:provider/provider.dart'.

Format lib/persist_theme.dart.

Run flutter format to format lib/persist_theme.dart.

Maintenance issues and suggestions

Support latest dependencies. (-5 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
flutter_material_color_picker ^1.0.0 1.0.0
localstorage ^2.0.0 2.0.0
provider ^3.0.0+1 3.0.0+1
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
path_provider 1.1.0
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test