import 'package:dio/dio.dart'; import 'package:json_annotation/json_annotation.dart'; part 'base_model.g.dart'; @JsonSerializable() class BaseModel { int code; String msg; dynamic data; BaseModel({ required this.code, required this.msg, this.data, }); List map(T Function(dynamic json) f) { if (data == null) return []; return (data! as List).map(f).toList(); } factory BaseModel.unknown() => BaseModel( code: -1, msg: 'UNKNOW FAIL', ); factory BaseModel.dioErr(DioError err) => BaseModel( code: err.response?.statusCode ?? -1, msg: err.message, ); factory BaseModel.fromJson(Map json) => _$BaseModelFromJson(json) as BaseModel; }