Coder Social home page Coder Social logo

bartektartanus / pref_dessert Goto Github PK

View Code? Open in Web Editor NEW
12.0 12.0 3.0 67 KB

Package that allows you persist objects as shared preferences easily.

Home Page: https://pub.dartlang.org/packages/pref_dessert

License: BSD 3-Clause "New" or "Revised" License

Dart 100.00%
dart flutter persisting-objects sharedpreferences

pref_dessert's People

Contributors

bartektartanus avatar yousifk avatar

Stargazers

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

Watchers

 avatar  avatar

pref_dessert's Issues

Optimize method DesSer<T> with json_serializable

Hi every one.
I optimized method DesSer with json_serializable.. I show code below. Hope.It will help you.

Step 1: import library json_serializable. in pubspec.yaml

dependencies:
  flutter:
    sdk: flutter
  pref_dessert: ^0.4.0+1
  json_serializable: ^3.2.2
  cupertino_icons: ^0.1.2
  json_annotation: ^3.0.0

dev_dependencies:
  flutter_test:
    sdk: flutter
  build_runner: ^1.0.0

Step 2: Create User class

import 'package:pref_dessert/pref_dessert.dart';
import 'package:timesheet/utils/constants.dart';
import 'package:json_annotation/json_annotation.dart';

part 'user.g.dart';

@JsonSerializable()
class User {
  var uid = "";
  var photoUrl = "";
  var displayName = "";
  var email = "";

  User({this.uid, this.photoUrl, this.displayName, this.email});
}

class UserDesSer extends JsonDesSer<User> {
  @override
  String get key => PREF_USER;

  @override
  User fromMap(Map<String, dynamic> map) => _$UserFromJson(map);

  @override
  Map<String, dynamic> toMap(User user) => _$UserToJson(user);
}

Step 3: Run command : flutter pub run build_runner build

How to save only object

Hello admin. I use pref_dessert save data.

repo.save(User(
        uid: user.uid,
        photoUrl: user.photoUrl,
        displayName: user.displayName,
        email: user.email));

And get data

repo.findAll();

But I want save only object. Example

repo.save(String key, Object object)

and get

repo.find(String key);

Please add method. thank you very much.

key feature is not working.

I have two classes of DesSer<Song>. I have used two different keys ( overridden the get key method of DesSer<Song> classes ) for both of them. But the data of both are saved same.
Is this a bug?

Reference: this class
and this class

How to add the items received from the repo into a list

I'm making a todo app, and I have a custom class called 'ToDoItem'

class ToDoItem extends StatelessWidget {
  ToDoItem({Key key, this.title, this.details}) : super(key: key);

  String title;
  String details = "Add some";
  Color tagColor = Colors.blue;
  var tags = <String>[];
  DateTime dueDate = DateTime.utc(
      DateTime.now().year, DateTime.now().month, DateTime.now().day + 1);

  @override
  Widget build(BuildContext context) {
    return Text(title);
  }
}

I want to be able to have the items inputted by the user automatically saved to the repo, and then re-added to the list when the app is refreshed.

The way I've attempted to accomplish this so far is with an async function

Future addItems() async {
    var list = repo.findAll();
    if(!hasInitialised){
      list != null ? _items.addAll(await list) : _items.add(ToDoItem(title: "this is a test"));
      hasInitialised = true;
      print("add saved items");
    }
  }

Yet no items are added to the list.
Any help would be appreciated.

Return the Future wherever applicable.

I found myself in a situation where I wanted to wait until removeAll() was done but the return type of it was void.

It would be intuitive to return the Future. I've fixed it in my local code and thought this is what others might experience as well so might as well include it in the official branch.

I can try to make a PR if necessary.

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.