Example ItemModel:
class ItemModel {
final int id;
final String name;
ItemModel({required this.id, required this.name});
factory ItemModel.fromJson(Map<String, dynamic> json) {
return ItemModel(
id: json['id'],
name: json['name'],
);
}
Map<String, dynamic> toJson() {
return {
'id': id,
'name': name,
};
}
}
You can adapt this pattern to your own entities (e.g.,
User,Post,Product, etc.).
Repositories combine the factory mixins provided by laravel_rest_api_flutter:
class ItemRepository
with
SearchFactory<ItemModel>,
DeleteFactory<ItemModel>,
MutateFactory<ItemModel>,
ActionsFactory<ItemModel> {
@override
String get baseRoute => '/items';
@override
ItemModel fromJson(Map<String, dynamic> json) => ItemModel.fromJson(json);
}
This repository now exposes methods like:
search(...)mutate(...)delete(...)actions(...)and keeps everything strongly-typed around ItemModel.