persist_theme 0.0.3+6

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

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:scoped_model/scoped_model.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final ThemeModel _model = ThemeModel();

  @override
  void initState() {
    try {
      _model.loadFromDisk();
    } catch (e) {
      print("Error Loading Theme: $e");
    }
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return ScopedModel<ThemeModel>(
      model: _model,
      child: new ScopedModelDescendant<ThemeModel>(
        builder: (context, child, model) => MaterialApp(
              theme: model.theme,
              home: HomeScreen(),
            ),
      ),
    );
  }
}

class HomeScreen extends StatelessWidget {
  @override
  Widget build(BuildContext 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(type: PickerType.block)),
                    Flexible(child: AccentColorPicker(type: PickerType.block)),
                  ],
                ),
                DarkAccentColorPicker(type: PickerType.block),
              ]
            : <Widget>[
                DarkModeSwitch(),
                TrueBlackSwitch(),
                CustomThemeSwitch(),
                PrimaryColorPicker(type: PickerType.block),
                AccentColorPicker(type: PickerType.block),
                DarkAccentColorPicker(type: PickerType.block),
              ],
      ),
    );
  }
}

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 #

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:scoped_model/scoped_model.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final ThemeModel _model = ThemeModel();

  @override
  void initState() {
    try {
      _model.loadFromDisk();
    } catch (e) {
      print("Error Loading Theme: $e");
    }
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return ScopedModel<ThemeModel>(
      model: _model,
      child: new ScopedModelDescendant<ThemeModel>(
        builder: (context, child, model) => MaterialApp(
              theme: model.theme,
              home: HomeScreen(),
            ),
      ),
    );
  }
}

class HomeScreen extends StatelessWidget {
  @override
  Widget build(BuildContext 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(type: PickerType.block)),
                    Flexible(child: AccentColorPicker(type: PickerType.block)),
                  ],
                ),
                DarkAccentColorPicker(type: PickerType.block),
              ]
            : <Widget>[
                DarkModeSwitch(),
                TrueBlackSwitch(),
                CustomThemeSwitch(),
                PrimaryColorPicker(type: PickerType.block),
                AccentColorPicker(type: PickerType.block),
                DarkAccentColorPicker(type: PickerType.block),
              ],
      ),
      floatingActionButton: FloatingActionButton(
        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: ^0.0.3+6

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages 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
0.0.3+6 Mar 4, 2019 Go to the documentation of persist_theme 0.0.3+6 Download persist_theme 0.0.3+6 archive
0.0.3+5 Mar 4, 2019 Go to the documentation of persist_theme 0.0.3+5 Download persist_theme 0.0.3+5 archive
0.0.3+4 Mar 4, 2019 Go to the documentation of persist_theme 0.0.3+4 Download persist_theme 0.0.3+4 archive
0.0.3+3 Mar 4, 2019 Go to the documentation of persist_theme 0.0.3+3 Download persist_theme 0.0.3+3 archive
0.0.3+2 Mar 4, 2019 Go to the documentation of persist_theme 0.0.3+2 Download persist_theme 0.0.3+2 archive
0.0.3+1 Mar 4, 2019 Go to the documentation of persist_theme 0.0.3+1 Download persist_theme 0.0.3+1 archive
0.0.3 Mar 4, 2019 Go to the documentation of persist_theme 0.0.3 Download persist_theme 0.0.3 archive
0.0.2+1 Feb 25, 2019 Go to the documentation of persist_theme 0.0.2+1 Download persist_theme 0.0.2+1 archive
0.0.2 Feb 25, 2019 Go to the documentation of persist_theme 0.0.2 Download persist_theme 0.0.2 archive
0.0.1 Feb 25, 2019 Go to the documentation of persist_theme 0.0.1 Download persist_theme 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
38
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
67
Learn more about scoring.

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

  • Dart: 2.2.0
  • pana: 0.12.14
  • Flutter: 1.3.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
flutter_colorpicker ^0.2.1 0.2.1
path_provider ^0.5.0+1 0.5.0+1
scoped_model ^1.0.1 1.0.1
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test