storage_ui 1.0.6 copy "storage_ui: ^1.0.6" to clipboard
storage_ui: ^1.0.6 copied to clipboard

A powerful and user-friendly library for managing saved key-value pairs in Flutter, built on top of get_storage and flutter_secure_storage.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:get_storage/get_storage.dart';
import 'package:storage_ui/core/storage.dart';
import 'package:storage_ui/storage_ui.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await GetStorage.init();
  await GetStorage().write(
    'test time',
    "2022-12-08",
  );
  await GetStorage().write(
    'test',
    "some String",
  );
  await GetStorage().write(
    'test text',
    {
      "key": "value",
    },
  );
  runApp(const App());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: CacheStorageLogPage(
        cacheStorage: GetStorageImpl(GetStorage()),
        pageStyle: PageStyle(
          appBarColor: Colors.blue,
          backgroundCursorColor: Colors.black26,
          confirmColor: Colors.green,
          cursorColor: Colors.black,
          textColor: Colors.black,
          confirmButtonTextColor: Colors.green,
          resetButtonTextColor: Colors.red,
        ),
        onError: (message) {
          print(message);
        },
      ),
    );
  }
}

//
class GetStorageImpl extends Storage {
  final GetStorage storage;
  GetStorageImpl(this.storage);

  @override
  Future<void> delete(String key) async {
    return await storage.remove(key);
  }

  @override
  Future<List<String>> getKeys() async {
    return List<String>.from(storage.getKeys());
  }

  @override
  Future<T?> read<T>(String key) async => storage.read(key);

  @override
  Future<void> write(String key, value) async =>
      await storage.write(key, value);
//   final getStorage = GetStorage();
//   final getStorage = const FlutterSecureStorage();
//
//
//   SecureStorage.withOptions({
//     WebOptions? webOptions,
//     WindowsOptions? windowsOptions,
//     AndroidOptions? androidOptions,
//     IOSOptions? iosOptions,
//     MacOsOptions? macOsOptions,
//     LinuxOptions? linuxOptions,
//   }) : secureStorage = FlutterSecureStorage(
//     webOptions: webOptions ?? WebOptions.defaultOptions,
//     aOptions: androidOptions ?? AndroidOptions.defaultOptions,
//     iOptions: iosOptions ?? IOSOptions.defaultOptions,
//     lOptions: linuxOptions ?? LinuxOptions.defaultOptions,
//     mOptions: macOsOptions ?? MacOsOptions.defaultOptions,
//     wOptions: windowsOptions ?? WindowsOptions.defaultOptions,
//   );
//
//   /// Retrieves a list of keys for all stored values
//   @override
//   Future<List<String>> getKeys() async => getStorage.getKeys().toList();
//
//   /// Retrieves a stored value by its key
//   @override
//   Future<T?> read<T>(String key) async => getStorage.read<T>(key);
//
//   /// Stores a value by its key
//   @override
//   Future<void> write(String key, value) async =>
//       await getStorage.write(key, value);
//
//   /// Removes a stored value by its key
//   @override
//   Future<void> delete(String key) async => await getStorage.remove(key);
//
//
//   @override
//   Future<List<String>> getKeys() async {
//     final data = await secureStorage.readAll();
//     return data.keys.toList();
//   }
//
//   @override
//   Future<T?> read<T>(String key) async {
//     return await secureStorage.read(key: key) as T;
//   }
//
//   @override
//   Future<void> write(String key, value) async =>
//       await secureStorage.write(key: key, value: value);
//
//   @override
//   Future<void> delete(String key) async => await secureStorage.delete(key: key);
}
4
likes
160
pub points
63%
popularity

Publisher

verified publisherappsgateway.website

A powerful and user-friendly library for managing saved key-value pairs in Flutter, built on top of get_storage and flutter_secure_storage.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on storage_ui