flutter_session_manager

Last updated:

0 purchases

flutter_session_manager Image
flutter_session_manager Images
Add to Cart

Description:

flutter session manager

flutter_session_manager #

Adds an easy to use wrapper to session management in flutter. Allows for easy session storage and management. The session persists in the app's' lifetime.

Store values in the session: #
await SessionManager().set("key", value);
copied to clipboard
or
var sessionManager = SessionManager();
await sessionManager.set("name", "cool user");
await sessionManager.set("id", 3);
await sessionManager.set("measure", 23.2);
await sessionManager.set("isLoggedIn", true);
await sessionManager.set("user", new User(id: 1, name: "John", isCool: true, postCount: 4));
copied to clipboard
Read values from the session: #
dynamic id = await SessionManager().get("id");
copied to clipboard
Saving objects: #
To save objects, the class must have the toJson() method implemented. When getting a object, it returns as a Json that you can Serialize using fromJson() method.
class User {
final int id;
final String name;
final bool isCool;
final int postCount;

User({this.id, this.name, this.isCool, this.postCount});

Map<String, dynamic> toJson() {
final Map<String, dynamic> user = Map<String, dynamic>();
user["id"] = id;
user["name"] = this.name;
user["isCool"] = this.isCool;
user["postCount"] = this.postCount;
return user;
}
}

User user = User(id: 1, name: "John", isCool: true, postCount: 4);
await SessionManager().set('user', user);
User u = User.fromJson(await SessionManager().get("user"));
copied to clipboard
Session Management: #
This package contains all operations that may be necessary to manage a session.

Update session

await SessionManager().update();
copied to clipboard

Delete session and all data in it

await SessionManager().destroy();
copied to clipboard

Remove a specific item

await SessionManager().remove("id");
copied to clipboard

Verify wether or not a key exists

await SessionManager().containsKey("id"); // true or false
copied to clipboard
Getting Started #
With Flutter, run:
$ flutter pub add flutter_session_manager
copied to clipboard
This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get):
dependencies:
flutter_session_manager: ^1.0.3
copied to clipboard
To import it in your Dart code, you can use:
import 'package:flutter_session_manager/flutter_session_manager.dart';

Contributing #
Contributions are what make the open source community such an amazing place to be learn, inspire, and create.


Fork the Project


Create your Feature Branch (git checkout -b feature/AmazingFeature)


Commit your Changes (git commit -m 'Add some AmazingFeature')


Push to the Branch (git push origin feature/AmazingFeature)


Open a Pull Request



License #
Distributed under the MIT License. See LICENSE for more information.
Copyright (c) Eduardo Migueis 2021.

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.