entity_factory.dart 421 B

12345678910111213
  1. import 'package:flutter_provider_demo/model/base_model.dart';
  2. import 'package:flutter_provider_demo/model/user_model.dart';
  3. class EntityFactory {
  4. // 把api获得的 json 中的 data 字段于Model 绑定
  5. static T generateOBJ<T>(dynamic json) {
  6. if (T.toString() == "UserEntity") {
  7. return UserEntity.fromJson(json) as T;
  8. } else {
  9. return BaseEntity(code: -1, msg: "No such Model") as T;
  10. }
  11. }
  12. }