Giter Site home page Giter Site logo

flutter_session's Introduction

flutter_session

Adds session support to Flutter. Works with mobile, web and (hopefully) desktop builds. (Don't forget to hit the like button if you find the package helpful.)

Write values to the session:

await FlutterSession().set("token", myJWTToken);

or

var session = FlutterSession();
await session.set("token", myJWTToken);
await session.set("name", "jhourlad");
await session.set("id", 1);
await session.set("price", 10.50);
await session.set("isOK", true);

Saving objects, make sure that it has the toJson() method. See https://ashamp.github.io/jsonToDartModel:

class Data {
  final int id;
  final String data;

  Data({this.data, this.id});

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

Data mappedData = Data(id: 1, data: "Lorem ipsum something, something...");
await FlutterSession().set('mappedData', mappedData);

Read values from the session:

dynamic token = await FlutterSession().get("token");

Session persists throughout the app's lifetime. (Don't forget to hit the like button if you find the package helpful.)

flutter_session's People

Contributors

jhourlad01 avatar romanivn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

flutter_session's Issues

version solving failed

am building a Flutter web app and I wanted to add sessions, so I tried adding the flutter_session package using flutter pub add flutter_session but I get this error

Because shared_preferences_linux >=0.0.4-nullsafety <2.0.0 depends on shared_preferences_platform_interface ^2.0.0-nullsafety and shared_preferences_linux <=0.0.2 depends on path_provider ^1.6.11, shared_preferences_linux <0.0.2+1 or >=0.0.4-nullsafety <2.0.0-โˆž requires shared_preferences_platform_interface ^2.0.0-nullsafety or path_provider ^1.6.11.
And because shared_preferences_linux >=0.0.2+1 <0.0.4-nullsafety depends on path_provider_linux ^0.0.1 and shared_preferences >=0.5.8 <2.0.0-nullsafety depends on shared_preferences_linux ^0.0.2, shared_preferences >=0.5.8 <2.0.0-nullsafety requires path_provider_linux ^0.0.1 or shared_preferences_platform_interface ^2.0.0-nullsafety or path_provider ^1.6.11.
And because shared_preferences >=0.5.4+8 <2.0.0-nullsafety depends on shared_preferences_platform_interface ^1.0.0 and path_provider >=2.0.0 depends on path_provider_linux ^2.0.0, path_provider >=2.0.0 is incompatible with shared_preferences >=0.5.8 <2.0.0-nullsafety.
And because google_fonts >=2.0.0 depends on path_provider ^2.0.0 and every version of flutter_session depends on shared_preferences ^0.5.8, google_fonts >=2.0.0 is incompatible with flutter_session.
So, because admin depends on both google_fonts ^2.0.0 and flutter_session any, version solving failed.

i tried removing google_fonts package but the same issue remained but this time with other packages.
this one after removing google_fonts

(1) So, because path_provider_platform_interface <2.0.0-nullsafety depends on plugin_platform_interface ^1.0.1, cloud_firestore >=2.2.2 is incompatible with path_provider_platform_interface <2.0.0-nullsafety.

    Because shared_preferences_linux >=0.0.2+1 <0.0.4-nullsafety depends on path_provider_linux ^0.0.1 and shared_preferences_linux <=0.0.2 depends on path_provider ^1.6.11, shared_preferences_linux <0.0.4-nullsafety requires path_provider_linux ^0.0.1 or path_provider ^1.6.11.
    And because path_provider_linux <0.2.0-nullsafety depends on path_provider_platform_interface ^1.0.1 and path_provider >=1.6.4 <2.0.0-nullsafety depends on path_provider_platform_interface ^1.0.1, shared_preferences_linux <0.0.4-nullsafety requires path_provider_platform_interface ^1.0.1.
(2) So, because cloud_firestore >=2.2.2 is incompatible with path_provider_platform_interface <2.0.0-nullsafety (1), cloud_firestore >=2.2.2 is incompatible with shared_preferences_linux <0.0.4-nullsafety.

    Because shared_preferences_linux >=0.0.4-nullsafety <2.0.0 depends on shared_preferences_platform_interface ^2.0.0-nullsafety and shared_preferences >=0.5.8 <2.0.0-nullsafety depends on shared_preferences_linux ^0.0.2, shared_preferences >=0.5.8 <2.0.0-nullsafety requires shared_preferences_platform_interface ^2.0.0-nullsafety or shared_preferences_linux >=0.0.2 <0.0.4-nullsafety.
    And because shared_preferences >=0.5.4+8 <2.0.0-nullsafety depends on shared_preferences_platform_interface ^1.0.0, shared_preferences >=0.5.8 <2.0.0-nullsafety requires shared_preferences_linux >=0.0.2 <0.0.4-nullsafety.
    And because cloud_firestore >=2.2.2 is incompatible with shared_preferences_linux <0.0.4-nullsafety (2), cloud_firestore >=2.2.2 is incompatible with shared_preferences >=0.5.8 <2.0.0-nullsafety.
    And because every version of flutter_session depends on shared_preferences ^0.5.8, cloud_firestore >=2.2.2 is incompatible with flutter_session.
    So, because admin depends on both cloud_firestore ^2.2.2 and flutter_session any, version solving failed.
pub finished with exit code 65

how add multiple maps

Hello guys, i need helpe.
how add multiple maps ?
Exemple: {id:1,name:test},{id:2,name:test2}

there is a problem when add list string

List data = List();
data.add('${map['id']}:${map['valor']}');
await FlutterSession().set("beneficios", data);

Exception has occurred.
NoSuchMethodError (NoSuchMethodError: Class 'List' has no instance method 'toJson'.
Receiver: Instance(length:1) of '_GrowableList'
Tried calling: toJson())

  // List<String>
  case List:
    {
      this.prefs.setStringList(key, value);
    }

Clear

Possibility to remove all sessions?

SharedPreferences preferences = await SharedPreferences.getInstance();
await preferences.clear();

null safety

can u guys please update the package to support null safety thank you.
Screenshot 2022-03-28 100347

flutter 2.x bug

Hello sir.

flutter_session seems to be incompatible with other third-party libraries.

Can you schedule an update to the null safe version recently?

[study] flutter pub get
Running "flutter pub get" in study...
Because study depends on flutter_session ^0.1.1 which depends on shared_preferences ^0.5.8, shared_preferences ^0.5.8 is required.

So, because study depends on shared_preferences ^2.0.3, version solving failed.
pub get failed (1; So, because study depends on shared_preferences ^2.0.3, version solving failed.)
exit code 1

Web issue with runtimetype

If I create a session variabel like this:

FlutterSession().set('token', '12345');

then on web, the token will be stored like an integer and not a string.

Is it probable a issue with the webbuild and not your package?

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.