what is wrong in my code : ArabicEnglish? toArabicEnglishModel(dynamic value, String?…
- User
what is wrong in my code : ArabicEnglish? toArabicEnglishModel(dynamic value, String? parentId) { try { print('start print : $value'); print(value['id']); print(value['nameArb']); print(value['nameArb']); if (value == null) { return null; } else if (value is ArabicEnglish) { return value; } else { (value is Map<String, dynamic>); return ArabicEnglish( id: value['id'], nameArb: value['nameArb'], nameEng: value['nameEng'], parentId: parentId); } } catch (e) { print('error heppen'); if (e is FormatException) { throw const FormatException('Cannot convert to ArabicEnglish'); } else { print(e.toString()); // Handle other exceptions } } }
- Assistant
There are a few errors in your code:
-
The line
(value is Map<String, dynamic>);does not serve any purpose. It is not assigning the result of the check to a variable or performing any operation. You can remove this line. -
In the line
print(value['nameArb']);, you are printingvalue['nameArb']twice. You can remove one of the print statements.
Here's the updated code:
codeArabicEnglish? toArabicEnglishModel(dynamic value, String? parentId) { try { print('start print : $value'); print(value['id']); print(value['nameArb']); if (value == null) { return null; } else if (value is ArabicEnglish) { return value; } else { return ArabicEnglish( id: value['id'], nameArb: value['nameArb'], nameEng: value['nameEng'], parentId: parentId); } } catch (e) { print('error happened'); if (e is FormatException) { throw const FormatException('Cannot convert to ArabicEnglish'); } else { print(e.toString()); // Handle other exceptions } } } -