Giter VIP home page Giter VIP logo

brian2694 / glutton Goto Github PK

View Code? Open in Web Editor NEW

This project forked from agungnursatria/glutton

1.0 1.0 0.0 90 KB

Flutter shared preferences customized plugin. Secure, Encrypted, Simplified use, Simple key-value pairs storage.

Home Page: https://pub.dev/packages/glutton

License: BSD 3-Clause "New" or "Revised" License

Dart 90.58% Kotlin 0.93% Ruby 7.53% Swift 0.88% Objective-C 0.08%

glutton's Introduction

Glutton

Flutter shared preferences customized plugin. Secure, Encrypted, Simplified use, Simple key-value pairs storage.

Getting Started

In your flutter project add the dependency:

dependencies:
  ...
  glutton: ^1.0.5

Usage

Importing package

import 'package:glutton/glutton.dart';

Using Glutton

Saving data inside glutton

bool isSuccess = await Glutton.eat(key, data);

Retrieve data inside glutton

dynamic data = await Glutton.vomit(key);

Check if data is exist inside glutton

bool isExist = await Glutton.have(key);

Remove data inside glutton

bool isSuccess = await Glutton.digest(key);

Clear all data inside glutton

await Glutton.flush();

Can we save class object?

The current answer is no.

Written in JSON and Serialization, flutter doesn't provide library like GSON or Moshi. Such a library would require using runtime reflection, which is disabled in Flutter. So we can't automatically turn class into json or the opposite, but we need to transform it manual first to edible data type.

Edible data type

  • List
  • Set
  • Map (can eat json here)
  • DateTime
  • String
  • bool
  • int (can eat enum index here)
  • double
  • Uri

Example

Save:

/// 1. Create user object
User user = User(
  name: "Gentleton",
  age: 21,
  createdAt: DateTime.now(),
);

/// 2. Transform user object to map
Map<String, dynamic> userMap = user.toJson();

/// 3. Save user map inside glutton
bool isSuccess = await Glutton.eat(<UserKey>, userMap);

Retrieve

/// 1. Retrieve user map inside glutton
Map<String, dynamic> userMap = await Glutton.vomit(<UserKey>);

/// 2. Transform user map to user object
User user = User.fromJson(userMap);

Save:

/// 1. Set selected date
DateTime date = await showDatePicker(
  context: context,
  initialDate: _selectedDate,
  firstDate: DateTime(1990),
  lastDate: DateTime(2030),
);

/// 2. Save selected date inside glutton
await Glutton.eat(<DateKey>, date);

Retrieve

/// 1. Retrieve user map inside glutton
DateTime date = await Glutton.vomit(<DateKey>);

Save:

/// 1. Retrieve index of enum
int index = Season.index;

/// 2. Save index inside glutton
await Glutton.eat(<enumKey>, index);

Retrieve

/// 1. Retrieve index inside glutton
int index = await Glutton.vomit(<enumKey>);

/// 2. Transform index to enum
Season _season = SeasonManager.fromIndex(index);

You can follow Season enum for step 2 retrieve enum

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.