secure_shared_preferences 0.0.4 copy "secure_shared_preferences: ^0.0.4" to clipboard
secure_shared_preferences: ^0.0.4 copied to clipboard

Simple to use yet powerful package to encypt shared preferences in android and UserDefaults in iOS.

example/lib/main.dart

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

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

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

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final TextEditingController _controller = TextEditingController();
  String? data = "";

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            TextField(
              controller: _controller,
            ),
            Text(data ?? ""),
            MaterialButton(
              onPressed: _getData,
              child: const Text("Get It Back"),
            )
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _save,
        tooltip: 'Save',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }

  void _save() async {
    var pref = await SecureSharedPref.getInstance();
    pref.putString("StringEncrypted", "This is my first string test", isEncrypted:true);
  }

  _getData() {
    SecureSharedPref.getInstance().then((value) {
      value.getString("StringEncrypted",isEncrypted: true).then((value) {
        setState(() {
          data = value.toString();
        });
      });
    });
  }
}
23
likes
120
pub points
91%
popularity

Publisher

verified publisherflutter.pingtobuild.com

Simple to use yet powerful package to encypt shared preferences in android and UserDefaults in iOS.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (LICENSE)

Dependencies

cryptography, cryptography_flutter, flutter, flutter_secure_storage, package_info, shared_preferences

More

Packages that depend on secure_shared_preferences