http_resource 0.1.2 copy "http_resource: ^0.1.2" to clipboard
http_resource: ^0.1.2 copied to clipboard

This library allows you to simple map your models into crud objects that will automatically update it's values.

example/main.dart

import 'package:http_resource/http_resource.dart';

class Todo extends Model<Todo> {
  HttpClient httpClient = TodoClient();
  int userId;
  String title;
  String body;
  bool completed;

  Map<String, dynamic> get fields => {
        'id': this.id,
        'userId': userId,
        'title': title,
        'body': body,
        'completed': completed
      };

  @override
  Map<String, dynamic> setFields() => {
        "id": (value) => this.id = value,
        "userId": (value) => userId = value,
        "title": (value) => title = value,
        "body": (value) => body = value,
        "completed": (value) => completed = value,
      };
}

class TodoClient extends HttpClient<Todo> {
  @override
  String get apiUrl => 'https://jsonplaceholder.typicode.com/todos';

  @override
  Todo getInstance() {
    return Todo();
  }
}

void main() async {
  List<Todo> todo = await TodoClient().all();
  Todo test = await TodoClient().first(1);
  Todo create = Todo();
  create.userId = 1;
  create.title = 'testtitle';
  await create.create();
  create.id = 1;
  create.body = "trele body";
  await create.update();
}
0
likes
30
pub points
0%
popularity

Publisher

unverified uploader

This library allows you to simple map your models into crud objects that will automatically update it's values.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

http

More

Packages that depend on http_resource