encrypt_shared_preferences 0.9.9 copy "encrypt_shared_preferences: ^0.9.9" to clipboard
encrypt_shared_preferences: ^0.9.9 copied to clipboard

This package adds extra layer of protection to sensitive information like user credentials, API keys, or other confidential data stored in your app.

example/lib/main.dart

import 'dart:math';

import 'package:encrypt_shared_preferences/provider.dart';
import 'package:flutter/material.dart';

class CustomEncryptorAlgorithm implements IEncryptor {
  @override
  String decrypt(String key, String encryptedData) {
    const decryptedData = "";

    EncryptedSharedPreferencesAsync.getInstance().getKeys();
    return decryptedData;
  }

  @override
  String encrypt(String key, String plainText) {
    const encryptedTextBase64 = "";
    return encryptedTextBase64;
  }
}

void main() async {
  await EncryptedSharedPreferences.initialize('1111111111111111');
  EncryptedSharedPreferences.getInstance().setString('dataKey1', 'dataValue');
  EncryptedSharedPreferences.getInstance().setString('dataKey2', 'dataValue');
  EncryptedSharedPreferences.getInstance().setString('dataKey3', 'dataValue');
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: SharedBuilder(
          listenKeys: const {"key1", "key2"}, //Optional
          builder: (EncryptedSharedPreferences encryptedSharedPreferences,
              String? updatedKey) {
            return Text(
                "value : ${encryptedSharedPreferences.getString("key1")}");
          },
        ),
        appBar: AppBar(
          title: const Text('Shared Builder Demo'),
        ),
        floatingActionButton: Column(children: [
          FloatingActionButton(
            onPressed: () async {
              EncryptedSharedPreferences.getInstance()
                  .setString('key1', Random().nextInt(100).toString());
              Future.delayed(const Duration(seconds: 3), () {
                EncryptedSharedPreferences.getInstance()
                    .setString('key2', 'dataValue');
              });
            },
          ),
          FloatingActionButton(
            onPressed: () async {
              EncryptedSharedPreferences.getInstance()
                  .setString('Random key ${Random().nextInt(100)}', Random().nextInt(100).toString());
            }
          ),
        ],)
      ),
    );
  }
}
copied to clipboard
42
likes
140
points
8.85k
downloads

Publisher

unverified uploader

Weekly Downloads

2024.10.08 - 2025.04.22

This package adds extra layer of protection to sensitive information like user credentials, API keys, or other confidential data stored in your app.

Repository (GitHub)

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

devtools_shared, encrypt, flutter, shared_preferences

More

Packages that depend on encrypt_shared_preferences