flutter_session 0.1.1 icon indicating copy to clipboard operation
flutter_session: ^0.1.1 copied to clipboard

Adds session support to Flutter. Works with mobile, web and (hopefully) desktop builds.

example/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_session/flutter_session.dart';

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;
  }
}

class Page1 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Material(
      child: FutureBuilder(
          future: saveData(context),
          builder: (context, snapshot) {
            return Text("You will not see this");
          }),
    );
  }

  Future<void> saveData(context) async {
    Data myData = Data(data: "Lorem ipsum, something, something...", id: 1);

    await FlutterSession().set('myData', myData);
    Navigator.push(context, MaterialPageRoute(builder: (_context) => Page2()));
  }
}

class Page2 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Material(
        child: FutureBuilder(
            future: FlutterSession().get('myData'),
            builder: (context, snapshot) {
              return Text(snapshot.hasData
                  ? snapshot.data['id'].toString() + "|" + snapshot.data['data']
                  : 'Loading...');
            }));
  }
}
209
likes
110
pub points
92%
popularity

Publisher

unverified uploader

Adds session support to Flutter. Works with mobile, web and (hopefully) desktop builds.

Repository (GitHub)

Documentation

API reference

License

Icon for licenses.MIT (LICENSE)

Dependencies

flutter, shared_preferences

More

Packages that depend on flutter_session