Skip to content

TypeConverter error. #1199

Answered by simolus3
mytc asked this question in Q&A
May 17, 2021 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Thank you for starting this discussion. The example from the docs has not been migrated to null safety, which I think is causing the confusion here.

Something like this should work, the docs should update soon

class ListConverter extends TypeConverter<List<String>, String>{
  const ListConverter();
  @override
  List<String>? mapToDart(String? fromDb) { 
    if (fromDb == null || fromDb == '') {
      return null;
    }
    return json.decode(fromDb);
  }

  @override
  String? mapToSql(List<String>? value) {
    if (value == null || value.length == 0) {
      return null;
    }

    return json.encode(value);
  }
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@mytc
Comment options

Answer selected by mytc
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