user_preferences 0.1.1

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

User preferences

pub package

This is a port of Android SharedPreferences, providing, a persistent store for simple data. Data is persisted to disk asynchronously. This package does not guarantee that writes will be persisted to disk after returning and this library must not be used for storing critical data.

Usage

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

Example

import 'dart:io';

import 'package:user_preferences/user_preferences.dart';

void main() async {
  // Initialize the default value, after this I can use UserPreferences.instance
  await UserPreferences.init(Directory('/some/directory/that/I/can/use'));

  final String name = UserPreferences.instance.getString('name', 'Mike');
  print('My name is $name/');

  UserPreferences.instance.edit()
    ..putString('name', 'Joe')
    ..apply();
}

for flutter you can use it like this:

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';
import 'package:user_preferences/user_preferences.dart';

void main() async {
  final Directory baseDir = await getApplicationDocumentsDirectory();
  await UserPreferences.init(baseDir);

  runApp(MaterialApp(
    home: Scaffold(
      body: Center(
        child: RaisedButton(
          onPressed: _incrementCounter,
          child: Text('Increment Counter'),
        ),
      ),
    ),
  ));
}

void _incrementCounter() async {
  UserPreferences prefs = UserPreferences.instance;
  final int counter = (prefs.getInt('counter') ?? 0) + 1;
  print('Pressed $counter times.');

  prefs.edit()
    ..putInt('counter', counter)
    ..apply();
}

0.1.1 - December 3, 2018

  • add flutter example
  • initialize the base directory in getInstance()

0.0.1

  • Initial version

example/example.dart

// File created by
// Lung Razvan <long1eu>
// on 2018-12-03

import 'dart:io';

import 'package:user_preferences/user_preferences.dart';

void main() async {
  // Initialize the default value, after this I can use UserPreferences.instance
  await UserPreferences.init(Directory('/some/directory/that/I/can/use'));

  final String name = UserPreferences.instance.getString('name', 'Mike');
  print('My name is $name/');

  UserPreferences.instance.edit()
    ..putString('name', 'Joe')
    ..apply();
}

Use this package as a library

1. Depend on it

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


dependencies:
  user_preferences: ^0.1.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or 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:user_preferences/user_preferences.dart';
  
Version Uploaded Documentation Archive
0.1.1 Dec 3, 2018 Go to the documentation of user_preferences 0.1.1 Download user_preferences 0.1.1 archive
0.1.0+2 Dec 3, 2018 Go to the documentation of user_preferences 0.1.0+2 Download user_preferences 0.1.0+2 archive
0.1.0+1 Dec 3, 2018 Go to the documentation of user_preferences 0.1.0+1 Download user_preferences 0.1.0+1 archive
0.1.0 Dec 3, 2018 Go to the documentation of user_preferences 0.1.0 Download user_preferences 0.1.0 archive
0.0.1 Dec 3, 2018 Go to the documentation of user_preferences 0.0.1 Download user_preferences 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
14
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
57
Learn more about scoring.

We analyzed this package on Dec 5, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7

Platforms

Detected platforms: Flutter, other

Primary library: package:user_preferences/user_preferences.dart with components: io.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
path ^1.6.2 1.6.2
Dev dependencies
test ^1.5.1