Git Product home page Git Product logo

persistent's Introduction

Welcome to Persistent.

A code generator for locally persistent classes.


Installation

Add persistent as a dev dependency in your pubspec.yaml file. This contains the generator itself.

dev_dependencies:
    persistent:

Add persistent_annotations as a dependency in your pubspec.yaml file. This contains the annotations that act as markers for the generator.

dependencies:
    persistent_annotations:

Getting started

Import the annotations and the local storage service to be used.

SharedPreferences for example.

import 'package:persistent_annotations:persistent_annotations.dart';
import 'package:shared_preferences:shared_preferences.dart';

Now, you're set to go.

Usage

Let's explain with an example.

A local user session is to be persisted. The data to persist locally, are an access token and its expiration date.

Let's get to it. We'll call the model LocalSessionApi.

  1. First declare an abstract class for the generator. Its name can be LocalSessionApi with the suffix Base, which is LocalSessionApiBase.
abstract class LocalSessionApiBase {
    
}
  1. Add the data to be persisted as late fields.
abstract class LocalSessionApiBase {
   late String accessToken;

   late DateTime expirationDate;
}
  1. Annotate the class and its fields.
@persistent
abstract class LocalSessionApiBase {
   @Default('')
   late String accessToken;

   @Default('2022-9-10 15:04:07')
   late DateTime expirationDate;
}
  1. Finally, generate.
flutter packages pub run build_runner build --delete-conflicting-outputs

You can also watch for any changes in code and rebuild accordingly. This can be faster during development of the classes.

flutter packages pub run build_runner watch --delete-conflicting-outputs

Contributing

Everyone is more than welcomed to contribute to the code.

For any suggestions you can open an issue on github or DM me @ [email protected].

persistent's People

Contributors

ali-elganzory avatar

Watchers

 avatar  avatar  avatar

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.