flutter_session_manager
Flutter에서 세션 저장 및 관리를 지원하는 사용하기 쉬운 세션 래퍼입니다.
Flutter에서 세션 저장 및 관리를 지원하는 사용하기 쉬운 세션 래퍼입니다.
{"sdk":"flutter"}^2.0.8{"sdk":"flutter"}^1.0.0아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
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.
await SessionManager().set("key", value);
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));
dynamic id = await SessionManager().get("id");
To save objects, the class must have the toJson() method. 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"));
This package contains all operations that may be necessary to manage a session.
await SessionManager().update();
await SessionManager().destroy();
await SessionManager().remove("id");
await SessionManager().containsKey("id"); // true or false
With Flutter, run:
$ flutter pub add flutter_session_manager
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.1
To import it in your Dart code, you can use:
import 'package:flutter_session_manager/flutter_session_manager.dart';
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
Distributed under the MIT License. See LICENSE for more information.
Copyright (c) Eduardo Migueis 2021.