You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
here in the above example i am grouping expenses to their lower expense period. its like if i have 1500$ house rent expense and if i have to cover that in a month how much should i earn daily and its obviously 50$ and the same for yearly expense. and the new value is treated as daily expense and the only difference is the amount. it would be great if we can do this instead;
final e = someMonthlyExpense;
final dailyExpense = e.copyWith(amount: e.amount/30);
// this ^ is better and concise code than this/** Expenses( id: e.amount == amount ? e.id : 0, amount: e.amount/30, period: e.period, reason: e.reason, startDate: e.startDate,y endDate: e.endDate, createdAt: e.createdAt, );*/
it doesn't work because the toJson method changes the createdAt to String then when i use the fromJson method is complains type 'String' is not a subtype of type 'DateTime?'. the DateTime Field in the models should parse a String and DateTime types
NB. i added the copyWith method to the models but it resets everytime i change the schema.prisma and generate a client
The text was updated successfully, but these errors were encountered:
@kidusdev Fixed an issue with <model>.fromJson not being able to handle DateTime.
I actually want to wait for the macros (which are coming soon) to add the copyWith feature
Because along with that, we should not only add fromJson/toJson/copyWith to model, but also to input types. So that types can be published independently for the front end to use it.
Hy
I encounter this redundant code in various places of my application
here in the above example i am grouping expenses to their lower expense period. its like if i have 1500$ house rent expense and if i have to cover that in a month how much should i earn daily and its obviously 50$ and the same for yearly expense. and the new value is treated as daily expense and the only difference is the amount. it would be great if we can do this instead;
i tried
it doesn't work because the
toJson
method changes thecreatedAt
toString
then when i use thefromJson
method is complainstype 'String' is not a subtype of type 'DateTime?'
. the DateTime Field in the models should parse aString
andDateTime
typesNB. i added the
copyWith
method to the models but it resets everytime i change the schema.prisma and generate a clientThe text was updated successfully, but these errors were encountered: