api_response.dart 529 B

12345678910111213141516171819202122
  1. import 'package:json_annotation/json_annotation.dart';
  2. part 'api_response.g.dart';
  3. @JsonSerializable(genericArgumentFactories: true)
  4. class ApiResponse<T> {
  5. T? data;
  6. int code = 200;
  7. String msg = "";
  8. ApiResponse();
  9. factory ApiResponse.fromJson(
  10. Map<String, dynamic> json, T Function(Object? json) fromJsonT) =>
  11. _$ApiResponseFromJson(json, fromJsonT);
  12. Map<String, dynamic> toJson(Object Function(T value) toJsonT) =>
  13. _$ApiResponseToJson(this, toJsonT);
  14. bool get isSuccess => code == 200;
  15. }