MS Persist

Pub GitHub stars Buy Me A Coffee donate button

A mixin that help you on handling model as a CRUD

Getting Started

Is very simple to start use.

After set the lib in pubspec.yaml and run flutter pub get

import 'package:ms_persist/ms_persist.dart';

class YourModel with Persist<YourModel> {
  // .. a lot of another fields
  String someField;
  //TODO: implement field uuid
  @override
  String uuid;

  YourModel({this.uuid,this.someField/*other fields*/});

  //TODO: implement buildModel
  @override
  YourModel buildModel(Map<String, dynamic> map){
    return YourModel(
      uuid: map['uuid'],
      someField: map['someField'],
      );
  }

  //TODO: implement toMap
  @override
  Map<String, dynamic> toMap(){
    return {
      'uuid': this.uuid,
      'someField': someField,
      //TODO: add here every field or extra data that you want to save
    };
  }
}

// Now just use Persist to do hard word to persist data.
void main() async {
    var myModel = YourModel().find('42854c0c-018d-11eb-adc1-0242ac120002');
    myModel.someField = 'new value';
    await myModel.save();
    myModel.someField = 'other value';
    myModel.isDirty(); // returns true;
    await myModel.save();
    myModel.isDirty(); // returns false;
}

That's all folks!

I hope you enjoy this lib.

See another libs here

Libraries

ms_persist