Skip to content

string is not subtype of double #2672

Answered by simolus3
Panca6 asked this question in Q&A
Discussion options

You must be logged in to vote

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 RealColumn get price => real().map(const DoubleAsStringInJson())().

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Panca6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants