encrypted_shared_preferences 2.1.1 copy "encrypted_shared_preferences: ^2.1.1" to clipboard
encrypted_shared_preferences: ^2.1.1 copied to clipboard

outdated

This plugin stores Shared Preferences as encrypted values on device storage.

example/lib/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(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @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();
    init();
  }

  init() async {
    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('Encrypted Shared Preferences Demo Page'),
      ),
      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 != null && 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),
      ),
    );
  }
}
83
likes
40
pub points
95%
popularity

Publisher

unverified uploader

This plugin stores Shared Preferences as encrypted values on device storage.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

encrypt, shared_preferences

More

Packages that depend on encrypted_shared_preferences