extended_shared_preferences 1.0.0

  • Readme
  • Changelog
  • Installing
  • new62

Extended SharedPreferences #

This is an extension of the shared_preferences plugin so that the function of multiple SharedPreference files is now supported in iOS and in Android.

This plugin wraps NSUserDefaults (on iOS) and SharedPreferences (on Android), providing a persistent store for simple data. Data is persisted to disk asynchronously. Neither platform can guarantee that writes will be persisted to disk after returning and this plugin must not be used for storing critical data.

The deprecated commit() function is removed.

Getting Started #

Implement this plugin in your flutter project and use it with SharedPreferences.standard or SharedPreferences() to use the default preference store or use your own with SharedPreferences("[Your preference file]").

You can read values by calling

  /// Read a bool value.
  var v = SharedPreferences().getBool([Your Key]);

  /// Read an int value.
  var v = SharedPreferences().getInt([Your Key]);

  /// Read a double value.
  var v = SharedPreferences().getDouble([Your Key]);

  /// Read a string value.
  var v = SharedPreferences().getString([Your Key]);

  /// Read a string list value.
  var v = SharedPreferences().getStringList([Your Key]);

  /// Read any value.
  var v = SharedPreferences().get([Your Key]);

Write values by calling

  /// Write a bool value.
  SharedPreferences().setBool([Your Key], [Bool Value]);

  /// Write an int value.
  SharedPreferences().setInt([Your Key], [Int Value]);

  /// Write a double value.
  SharedPreferences().setDouble([Your Key], [Double Value]);
    
  /// Write a string value.
  SharedPreferences().setString([Your Key], [String Value]);
    
  /// Write a string list.
  SharedPreferences().setStringList([Your Key], [String List]);
    
  /// Write any value.
  SharedPreferences().set([Your Key], [Value]);

You can check if a key exists by calling

  SharedPreferences().containsKey([Your Key]);

You get a key set of all keys of the current file by calling

  var v = SharedPreferences().getKeys();

You can reload the values from the disk manually by calling

  SharedPreferences().reload();

Values can be removed by calling

  SharedPreferences().remove([Your Key]);

or

  SharedPreferences().clear();

if you want to clear all values of the preference file.

Usage #

To use this plugin, add extended_shared_preferences as a dependency in your pubspec.yaml file.

Example #

class AudioLevel extends StatefulWidget {
  @override
  _AudioLevelState createState() => _AudioLevelState();
}

class _AudioLevelState extends State<AudioLevel> {
  
  int audioLevel;
  
  final sharedPreferences = SharedPreferences("audioSettings");
  
  @override
  void initState() {
    audioLevel = sharedPreferences.getInt("audioLevel");
    super.initState();
  }
  
  @override
  Widget build(BuildContext context) {
    return Center(
      
      child: Column(
        children: <Widget>[
          Text("Current Level:"),
          Row(
            children: <Widget>[
              FlatButton(
                child: Icon(Icons.remove),
                onPressed: () => setState(() {
                  audioLevel--;
                  sharedPreferences.setInt("audioLevel", audioLevel);
                }),
              ),

              Text("$audioLevel"),

              FlatButton(
                child: Icon(Icons.add),
                onPressed: () => setState(() {
                  audioLevel++;
                  sharedPreferences.setInt("audioLevel", audioLevel);
                }),
              ),
            ],
          ),
        ],
      )
    );
  }
}

1.0.0 #

  • A extended version of the flutter shared_preferences plugin with a multi-sharedpreferences file function.

Use this package as a library

1. Depend on it

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


dependencies:
  extended_shared_preferences: ^1.0.0

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:extended_shared_preferences/MethodChannel.dart';
import 'package:extended_shared_preferences/SharedPreferences.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
29
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]
62
Learn more about scoring.

We analyzed this package on Jul 11, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.15
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform Linux

Because:

  • package:extended_shared_preferences/MethodChannel.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Web

Because:

  • package:extended_shared_preferences/MethodChannel.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Windows

Because:

  • package:extended_shared_preferences/MethodChannel.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform macOS

Because:

  • package:extended_shared_preferences/MethodChannel.dart that declares support for platforms: Android, iOS

Package not compatible with SDK dart

Because:

  • extended_shared_preferences that is a package requiring null.

Health suggestions

Format lib/MethodChannel.dart.

Run flutter format to format lib/MethodChannel.dart.

Format lib/SharedPreferences.dart.

Run flutter format to format lib/SharedPreferences.dart.

Maintenance suggestions

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and extended_shared_preferences.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test