preference_helper 0.0.5+2

  • Readme
  • Changelog
  • Example
  • Installing
  • 47

preference_helper #

Pub

A package that makes shared_preferences easier to use, This package is built with bloc, shared_preferences

Usage #

  • Initialize bloc
var sharedPreferences = await SharedPreferences.getInstance();
// Build PreferenceBloc with manage preference in bloc
var preferenceBloc = PreferenceBloc(
  sharedPreferences: sharedPreferences,
  usagePreferences: [
    Preference<int>(
      key: 'counter',
      initValue: 0,
    ),
  ],
);
  • Provide PreferenceBloc with BlocProvider
void main() async {
  var sharedPreferences = await SharedPreferences.getInstance();
  runApp(MyApp(
    preferenceBloc: PreferenceBloc(
      sharedPreferences: sharedPreferences,
      usagePreferences: [
        Preference<int>(
          key: 'counter',
          initValue: 0,
        ),
      ],
    ),
  ));
}

class MyApp extends StatelessWidget {
  final PreferenceBloc preferenceBloc;

  MyApp({@required this.preferenceBloc});

  @override
  Widget build(BuildContext context) {
    return BlocProvider<PreferenceBloc>(
      bloc: preferenceBloc,
      child: MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: MyHomePage(title: 'Flutter Demo Home Page'),
      ),
    );
  }
}
  • Set preference
var counterPref = state.preferences.get<int>("counter")
counterPref.value += 1;
preferenceBloc.dispatch(UpdatePreference(counterPref));
  • Use preferences in widget with BlocBuilder
@override
Widget build(BuildContext context) {
  return BlocBuilder<PreferenceEvent, PreferenceState>(
    bloc: BlocProvider.of<PreferenceBloc>(context),
    builder: (BuildContext context, PreferenceState state) {
      var counter = state.preferences.get<int>('counter').value;
      return Text(counter.toString());
    };
  );
}
  • Use preferences in widget without BlocBuilder
var prefCounter = preferenceBloc.getPreference<int>("counter");
print(prefCounter.value);

You can see this code blocks in example project. check this link

License #

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <http://unlicense.org>

0.0.5+2 #

  • Update dependencies (bloc, flutter_bloc to 0.13.0)

0.0.5+1 #

  • Change getPreference

0.0.5 #

  • Add wrapper class Preferences for preference lists use PreferenceState
  • Change preferences field type List
  • Rename getTypePreference
  • Change setPreference method to private, use dispatch event UpdatePreference instead of setPreference

0.0.4+1 #

  • Update documentation

0.0.4 #

  • Change bloc init state to loaded preference state
  • Remove PreferenceLoading, PreferenceLoaded state
  • Rename FetchPreference event to UpdatePreference

0.0.3 #

  • Add documentation comments
  • Change getPreferences method to public

0.0.2 #

  • Apply package layout convention

0.0.1 #

  • Initial release

example/README.md

preference_helper_example #

Example of use preference_helper

Use this package as a library

1. Depend on it

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


dependencies:
  preference_helper: ^0.0.5+2

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:preference_helper/preference_helper.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
9
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
60
Overall:
Weighted score of the above. [more]
47
Learn more about scoring.

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

  • Dart: 2.6.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Maintenance issues and suggestions

Support latest dependencies. (-30 points)

The version constraint in pubspec.yaml does not support the latest published versions for 3 dependencies (bloc, equatable, flutter_bloc).

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
bloc ^0.13.0 0.13.0 2.0.0
equatable ^0.2.3 0.2.6 1.0.0
flutter 0.0.0
flutter_bloc ^0.13.0 0.13.0 2.0.1
meta ^1.1.6 1.1.7 1.1.8
shared_preferences ^0.5.1+1 0.5.4+5
Transitive dependencies
collection 1.14.11 1.14.12
rxdart 0.22.6
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test