encrypted_shared_preferences 1.0.5

  • Readme
  • Changelog
  • Example
  • Installing
  • 84

Encrypted Shared Preferences #

Pub

This plugin stores Shared Preferences as encrypted values. It is decrypted when retrieved. You could use this side by side with regular Shared Preferences. Make sure to target iOS 9.0 and later if you're going to deploy for iOS.

Usage #

Instantiate class: #

EncryptedSharedPreferences encryptedSharedPreferences = EncryptedSharedPreferences();

Save value: #

encryptedSharedPreferences.setString('sample', 'Hello, World!').then((bool success) {
    if (success) {
        print('success');
    } else {
        print('fail');
    }
});

Retrieve value: #

encryptedSharedPreferences.getString('sample').then((String value) {
    print(value); /// Prints Hello, World!
});

Clear values: #

/// Clears all values, including those you saved using regular Shared Preferences.
encryptedSharedPreferences.clear().then((bool success) {
    if (success) {
        print('success');
    } else {
        print('fail');
    }
});

Dependencies #

This library depends on some other libraries :

[1.0.5] - 11/24/2019

  • Added clear option

[1.0.4] - 11/24/2019

  • Formatted lib/encrypted_shared_preferences.dart

[1.0.3] - 11/24/2019

  • Updated doc comments and README

[1.0.2] - 11/22/2019

  • Updated version number

[1.0.1] - 11/22/2019

  • Added example

[1.0.0] - 11/22/2019

  • Added null safety for getString.

[0.0.1] - 11/22/2019

  • initial release.

example/main.dart

import 'package:encrypted_shared_preferences/encrypted_shared_preferences.dart';
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Encrypted Shared Preferences Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Encrypted Shared Preferences Demo Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final EncryptedSharedPreferences encryptedSharedPreferences =
      EncryptedSharedPreferences();
  final _formKey = GlobalKey<FormState>();
  final myController = TextEditingController();
  String value = '';

  @override
  void initState() {
    super.initState();
    encryptedSharedPreferences.getString('sample').then((String _value) {
      setState(() {
        value = _value;
      });
    });
  }

  @override
  void dispose() {
    myController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Form(
          key: _formKey,
          child: Padding(
            padding: const EdgeInsets.all(8.0),
            child: Column(
              children: <Widget>[
                TextFormField(
                    decoration:
                        InputDecoration(hintText: 'Type text here and save'),
                    controller: myController,
                    validator: (value) {
                      if (value.isEmpty) {
                        return 'Please enter some text';
                      }
                      return null;
                    }),
                Text('Current value: $value')
              ],
            ),
          )),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          if (_formKey.currentState.validate()) {
            encryptedSharedPreferences
                .setString('sample', myController.text)
                .then((bool success) {
              if (success) {
                print('success');
                encryptedSharedPreferences
                    .getString('sample')
                    .then((String _value) {
                  setState(() {
                    value = _value;
                  });
                });
              } else {
                print('fail');
              }
            });
          }
        },
        tooltip: 'Save',
        child: Icon(Icons.save),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  encrypted_shared_preferences: ^1.0.5

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

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

  • Dart: 2.7.0
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5

Health issues and suggestions

Document public APIs. (-1 points)

8 out of 8 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
flutter_string_encryption ^0.3.1 0.3.1
shared_preferences ^0.5.4+5 0.5.6
Transitive dependencies
collection 1.14.11 1.14.12
flutter_web_plugins 0.0.0
meta 1.1.8
shared_preferences_macos 0.0.1+3
shared_preferences_platform_interface 1.0.1
shared_preferences_web 0.1.2+2
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test