-
price.dart @DataClassName('Price')
class PriceTable extends Table {
IntColumn get id => integer()();
RealColumn get price => real()();
@override
Set<Column> get primaryKey => {id};
} the error occured when i call here is the json format :
i know the error but how can i parse string to double? without writing my own custom UserRowClass(from json and to json)? |
Beta Was this translation helpful? Give feedback.
Answered by
simolus3
Oct 9, 2023
Replies: 1 comment
-
You could apply a type converter that only does its work for the JSON conversion to the column: class DoubleAsStringInJson extends TypeConverter<double, double>
with JsonTypeConverter2<double, double, String> {
const DoubleAsStringInJson();
@override
double fromJson(String json) => double.parse(json);
@override
String toJson(double value) => value.toString();
@override
double fromSql(double fromDb) => fromDb;
@override
double toSql(double value) => value;
} You can then apply it with |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Panca6
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could apply a type converter that only does its work for the JSON conversion to the column:
You can then apply it with
RealColumn get price => real().map(const DoubleAsStringInJson())()
.