123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- // ignore_for_file: non_constant_identifier_names
- // ignore_for_file: camel_case_types
- // ignore_for_file: prefer_single_quotes
- // This file is automatically generated. DO NOT EDIT, all your changes would be lost.
- import 'package:flutter/material.dart' show debugPrint;
- import 'package:domain/entity/auth_login_entity.dart';
- import 'package:domain/entity/captcha_img_entity.dart';
- import 'package:domain/entity/feedback_detail_entity.dart';
- import 'package:domain/entity/feedback_list_entity.dart';
- import 'package:domain/entity/form_list_entity.dart';
- import 'package:domain/entity/form_submitted_entity.dart';
- import 'package:domain/entity/form_submitted_page_entity.dart';
- import 'package:domain/entity/id_name_entity.dart';
- import 'package:domain/entity/newsfeed_comment_publish_entity.dart';
- import 'package:domain/entity/newsfeed_following_entity.dart';
- import 'package:domain/entity/newsfeed_foryou_entity.dart';
- import 'package:domain/entity/newsfeed_news_entity.dart';
- import 'package:domain/entity/property_news_entity.dart';
- import 'package:domain/entity/property_sale_rent_entity.dart';
- import 'package:domain/entity/server_time.dart';
- import 'package:domain/entity/user_me_entity.dart';
- JsonConvert jsonConvert = JsonConvert();
- typedef JsonConvertFunction<T> = T Function(Map<String, dynamic> json);
- typedef EnumConvertFunction<T> = T Function(String value);
- typedef ConvertExceptionHandler = void Function(Object error, StackTrace stackTrace);
- extension MapSafeExt<K, V> on Map<K, V> {
- T? getOrNull<T>(K? key) {
- if (!containsKey(key) || key == null) {
- return null;
- } else {
- return this[key] as T?;
- }
- }
- }
- class JsonConvert {
- static ConvertExceptionHandler? onError;
- JsonConvertClassCollection convertFuncMap = JsonConvertClassCollection();
- /// When you are in the development, to generate a new model class, hot-reload doesn't find new generation model class, you can build on MaterialApp method called jsonConvert. ReassembleConvertFuncMap (); This method only works in a development environment
- /// https://flutter.cn/docs/development/tools/hot-reload
- /// class MyApp extends StatelessWidget {
- /// const MyApp({Key? key})
- /// : super(key: key);
- ///
- /// @override
- /// Widget build(BuildContext context) {
- /// jsonConvert.reassembleConvertFuncMap();
- /// return MaterialApp();
- /// }
- /// }
- void reassembleConvertFuncMap() {
- bool isReleaseMode = const bool.fromEnvironment('dart.vm.product');
- if (!isReleaseMode) {
- convertFuncMap = JsonConvertClassCollection();
- }
- }
- T? convert<T>(dynamic value, {EnumConvertFunction? enumConvert}) {
- if (value == null) {
- return null;
- }
- if (value is T) {
- return value;
- }
- try {
- return _asT<T>(value, enumConvert: enumConvert);
- } catch (e, stackTrace) {
- debugPrint('asT<$T> $e $stackTrace');
- if (onError != null) {
- onError!(e, stackTrace);
- }
- return null;
- }
- }
- List<T?>? convertList<T>(List<dynamic>? value, {EnumConvertFunction? enumConvert}) {
- if (value == null) {
- return null;
- }
- try {
- return value.map((dynamic e) => _asT<T>(e, enumConvert: enumConvert)).toList();
- } catch (e, stackTrace) {
- debugPrint('asT<$T> $e $stackTrace');
- if (onError != null) {
- onError!(e, stackTrace);
- }
- return <T>[];
- }
- }
- List<T>? convertListNotNull<T>(dynamic value, {EnumConvertFunction? enumConvert}) {
- if (value == null) {
- return null;
- }
- try {
- return (value as List<dynamic>).map((dynamic e) => _asT<T>(e, enumConvert: enumConvert)!).toList();
- } catch (e, stackTrace) {
- debugPrint('asT<$T> $e $stackTrace');
- if (onError != null) {
- onError!(e, stackTrace);
- }
- return <T>[];
- }
- }
- T? _asT<T extends Object?>(dynamic value,
- {EnumConvertFunction? enumConvert}) {
- final String type = T.toString();
- final String valueS = value.toString();
- if (enumConvert != null) {
- return enumConvert(valueS) as T;
- } else if (type == "String") {
- return valueS as T;
- } else if (type == "int") {
- final int? intValue = int.tryParse(valueS);
- if (intValue == null) {
- return double.tryParse(valueS)?.toInt() as T?;
- } else {
- return intValue as T;
- }
- } else if (type == "double") {
- return double.parse(valueS) as T;
- } else if (type == "DateTime") {
- return DateTime.parse(valueS) as T;
- } else if (type == "bool") {
- if (valueS == '0' || valueS == '1') {
- return (valueS == '1') as T;
- }
- return (valueS == 'true') as T;
- } else if (type == "Map" || type.startsWith("Map<")) {
- return value as T;
- } else {
- if (convertFuncMap.containsKey(type)) {
- if (value == null) {
- return null;
- }
- var covertFunc = convertFuncMap[type]!;
- if (covertFunc is Map<String, dynamic>) {
- return covertFunc(value as Map<String, dynamic>) as T;
- } else {
- return covertFunc(Map<String, dynamic>.from(value)) as T;
- }
- } else {
- throw UnimplementedError('$type unimplemented,you can try running the app again');
- }
- }
- }
- //list is returned by type
- static M? _getListChildType<M>(List<Map<String, dynamic>> data) {
- if (<AuthLoginEntity>[] is M) {
- return data.map<AuthLoginEntity>((Map<String, dynamic> e) => AuthLoginEntity.fromJson(e)).toList() as M;
- }
- if (<CaptchaImgEntity>[] is M) {
- return data.map<CaptchaImgEntity>((Map<String, dynamic> e) => CaptchaImgEntity.fromJson(e)).toList() as M;
- }
- if (<FeedbackDetailEntity>[] is M) {
- return data.map<FeedbackDetailEntity>((Map<String, dynamic> e) => FeedbackDetailEntity.fromJson(e)).toList() as M;
- }
- if (<FeedbackDetailReplies>[] is M) {
- return data.map<FeedbackDetailReplies>((Map<String, dynamic> e) => FeedbackDetailReplies.fromJson(e)).toList() as M;
- }
- if (<FeedbackListEntity>[] is M) {
- return data.map<FeedbackListEntity>((Map<String, dynamic> e) => FeedbackListEntity.fromJson(e)).toList() as M;
- }
- if (<FeedbackItemEntity>[] is M) {
- return data.map<FeedbackItemEntity>((Map<String, dynamic> e) => FeedbackItemEntity.fromJson(e)).toList() as M;
- }
- if (<FormListEntity>[] is M) {
- return data.map<FormListEntity>((Map<String, dynamic> e) => FormListEntity.fromJson(e)).toList() as M;
- }
- if (<FormSubmittedEntity>[] is M) {
- return data.map<FormSubmittedEntity>((Map<String, dynamic> e) => FormSubmittedEntity.fromJson(e)).toList() as M;
- }
- if (<FormSubmittedContent>[] is M) {
- return data.map<FormSubmittedContent>((Map<String, dynamic> e) => FormSubmittedContent.fromJson(e)).toList() as M;
- }
- if (<FormSubmittedEstateOnlineForm>[] is M) {
- return data.map<FormSubmittedEstateOnlineForm>((Map<String, dynamic> e) => FormSubmittedEstateOnlineForm.fromJson(e)).toList() as M;
- }
- if (<FormSubmittedPageEntity>[] is M) {
- return data.map<FormSubmittedPageEntity>((Map<String, dynamic> e) => FormSubmittedPageEntity.fromJson(e)).toList() as M;
- }
- if (<IdNameEntity>[] is M) {
- return data.map<IdNameEntity>((Map<String, dynamic> e) => IdNameEntity.fromJson(e)).toList() as M;
- }
- if (<NewsfeedCommentPublishEntity>[] is M) {
- return data.map<NewsfeedCommentPublishEntity>((Map<String, dynamic> e) => NewsfeedCommentPublishEntity.fromJson(e)).toList() as M;
- }
- if (<NewsfeedFollowingEntity>[] is M) {
- return data.map<NewsfeedFollowingEntity>((Map<String, dynamic> e) => NewsfeedFollowingEntity.fromJson(e)).toList() as M;
- }
- if (<NewsfeedFollowingList>[] is M) {
- return data.map<NewsfeedFollowingList>((Map<String, dynamic> e) => NewsfeedFollowingList.fromJson(e)).toList() as M;
- }
- if (<NewsfeedFollowingListAccount>[] is M) {
- return data.map<NewsfeedFollowingListAccount>((Map<String, dynamic> e) => NewsfeedFollowingListAccount.fromJson(e)).toList() as M;
- }
- if (<NewsfeedForyouEntity>[] is M) {
- return data.map<NewsfeedForyouEntity>((Map<String, dynamic> e) => NewsfeedForyouEntity.fromJson(e)).toList() as M;
- }
- if (<NewsfeedForyouList>[] is M) {
- return data.map<NewsfeedForyouList>((Map<String, dynamic> e) => NewsfeedForyouList.fromJson(e)).toList() as M;
- }
- if (<NewsfeedForyouListAccount>[] is M) {
- return data.map<NewsfeedForyouListAccount>((Map<String, dynamic> e) => NewsfeedForyouListAccount.fromJson(e)).toList() as M;
- }
- if (<NewsfeedNewsEntity>[] is M) {
- return data.map<NewsfeedNewsEntity>((Map<String, dynamic> e) => NewsfeedNewsEntity.fromJson(e)).toList() as M;
- }
- if (<NewsfeedNewsList>[] is M) {
- return data.map<NewsfeedNewsList>((Map<String, dynamic> e) => NewsfeedNewsList.fromJson(e)).toList() as M;
- }
- if (<NewsfeedNewsListAccount>[] is M) {
- return data.map<NewsfeedNewsListAccount>((Map<String, dynamic> e) => NewsfeedNewsListAccount.fromJson(e)).toList() as M;
- }
- if (<PropertyNewsEntity>[] is M) {
- return data.map<PropertyNewsEntity>((Map<String, dynamic> e) => PropertyNewsEntity.fromJson(e)).toList() as M;
- }
- if (<PropertyNewsList>[] is M) {
- return data.map<PropertyNewsList>((Map<String, dynamic> e) => PropertyNewsList.fromJson(e)).toList() as M;
- }
- if (<PropertySaleRentEntity>[] is M) {
- return data.map<PropertySaleRentEntity>((Map<String, dynamic> e) => PropertySaleRentEntity.fromJson(e)).toList() as M;
- }
- if (<PropertySaleRentList>[] is M) {
- return data.map<PropertySaleRentList>((Map<String, dynamic> e) => PropertySaleRentList.fromJson(e)).toList() as M;
- }
- if (<ServerTime>[] is M) {
- return data.map<ServerTime>((Map<String, dynamic> e) => ServerTime.fromJson(e)).toList() as M;
- }
- if (<UserMeEntity>[] is M) {
- return data.map<UserMeEntity>((Map<String, dynamic> e) => UserMeEntity.fromJson(e)).toList() as M;
- }
- if (<UserMeHouseholds>[] is M) {
- return data.map<UserMeHouseholds>((Map<String, dynamic> e) => UserMeHouseholds.fromJson(e)).toList() as M;
- }
- if (<UserMeEstates>[] is M) {
- return data.map<UserMeEstates>((Map<String, dynamic> e) => UserMeEstates.fromJson(e)).toList() as M;
- }
- if (<UserMeEstatesAccounts>[] is M) {
- return data.map<UserMeEstatesAccounts>((Map<String, dynamic> e) => UserMeEstatesAccounts.fromJson(e)).toList() as M;
- }
- if (<UserMeEstatesAccountsUnit>[] is M) {
- return data.map<UserMeEstatesAccountsUnit>((Map<String, dynamic> e) => UserMeEstatesAccountsUnit.fromJson(e)).toList() as M;
- }
- if (<UserMeDefaultUnit>[] is M) {
- return data.map<UserMeDefaultUnit>((Map<String, dynamic> e) => UserMeDefaultUnit.fromJson(e)).toList() as M;
- }
- if (<UserMeInformation>[] is M) {
- return data.map<UserMeInformation>((Map<String, dynamic> e) => UserMeInformation.fromJson(e)).toList() as M;
- }
- debugPrint("$M not found");
- return null;
- }
- static M? fromJsonAsT<M>(dynamic json) {
- if (json is M) {
- return json;
- }
- if (json is List) {
- return _getListChildType<M>(json.map((dynamic e) => e as Map<String, dynamic>).toList());
- } else {
- return jsonConvert.convert<M>(json);
- }
- }
- }
- class JsonConvertClassCollection {
- Map<String, JsonConvertFunction> convertFuncMap = {
- (AuthLoginEntity).toString(): AuthLoginEntity.fromJson,
- (CaptchaImgEntity).toString(): CaptchaImgEntity.fromJson,
- (FeedbackDetailEntity).toString(): FeedbackDetailEntity.fromJson,
- (FeedbackDetailReplies).toString(): FeedbackDetailReplies.fromJson,
- (FeedbackListEntity).toString(): FeedbackListEntity.fromJson,
- (FeedbackItemEntity).toString(): FeedbackItemEntity.fromJson,
- (FormListEntity).toString(): FormListEntity.fromJson,
- (FormSubmittedEntity).toString(): FormSubmittedEntity.fromJson,
- (FormSubmittedContent).toString(): FormSubmittedContent.fromJson,
- (FormSubmittedEstateOnlineForm).toString(): FormSubmittedEstateOnlineForm.fromJson,
- (FormSubmittedPageEntity).toString(): FormSubmittedPageEntity.fromJson,
- (IdNameEntity).toString(): IdNameEntity.fromJson,
- (NewsfeedCommentPublishEntity).toString(): NewsfeedCommentPublishEntity.fromJson,
- (NewsfeedFollowingEntity).toString(): NewsfeedFollowingEntity.fromJson,
- (NewsfeedFollowingList).toString(): NewsfeedFollowingList.fromJson,
- (NewsfeedFollowingListAccount).toString(): NewsfeedFollowingListAccount.fromJson,
- (NewsfeedForyouEntity).toString(): NewsfeedForyouEntity.fromJson,
- (NewsfeedForyouList).toString(): NewsfeedForyouList.fromJson,
- (NewsfeedForyouListAccount).toString(): NewsfeedForyouListAccount.fromJson,
- (NewsfeedNewsEntity).toString(): NewsfeedNewsEntity.fromJson,
- (NewsfeedNewsList).toString(): NewsfeedNewsList.fromJson,
- (NewsfeedNewsListAccount).toString(): NewsfeedNewsListAccount.fromJson,
- (PropertyNewsEntity).toString(): PropertyNewsEntity.fromJson,
- (PropertyNewsList).toString(): PropertyNewsList.fromJson,
- (PropertySaleRentEntity).toString(): PropertySaleRentEntity.fromJson,
- (PropertySaleRentList).toString(): PropertySaleRentList.fromJson,
- (ServerTime).toString(): ServerTime.fromJson,
- (UserMeEntity).toString(): UserMeEntity.fromJson,
- (UserMeHouseholds).toString(): UserMeHouseholds.fromJson,
- (UserMeEstates).toString(): UserMeEstates.fromJson,
- (UserMeEstatesAccounts).toString(): UserMeEstatesAccounts.fromJson,
- (UserMeEstatesAccountsUnit).toString(): UserMeEstatesAccountsUnit.fromJson,
- (UserMeDefaultUnit).toString(): UserMeDefaultUnit.fromJson,
- (UserMeInformation).toString(): UserMeInformation.fromJson,
- };
- bool containsKey(String type) {
- return convertFuncMap.containsKey(type);
- }
- JsonConvertFunction? operator [](String key) {
- return convertFuncMap[key];
- }
- }
|