Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. // Handler for the network's request.
  2. abstract class RequestMapable {
  3. Map<String, dynamic> toJson();
  4. }
  5.  
  6. // Handler for the network's response.
  7. abstract class Mapable {
  8. factory Mapable(Mapable type, String data) {
  9. if (type is BaseMapable) {
  10. Map<String, dynamic> mappingData = json.decode(data);
  11. return type.fromJson(mappingData);
  12. } else if (type is ListMapable) {
  13. Iterable iterableData = json.decode(data);
  14. return type.fromJsonList(iterableData);
  15. }
  16.  
  17. return null;
  18. }
  19. }
  20.  
  21. abstract class BaseMapable<T> implements Mapable {
  22. Mapable fromJson(Map<String, dynamic> json);
  23. }
  24.  
  25. abstract class ListMapable<T> implements Mapable {
  26. Mapable fromJsonList(List<dynamic> json);
  27. }
  28.  
  29. // Handler for the network's error response.
  30. abstract class ErrorMapable implements BaseMapable {
  31. String errorCode;
  32. String description;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement