#community-help

Resolving Typesense Document Mapping Error in Flutter

TLDR Rude had issues mapping a typesense document into a dart object due to a 'Map' type error. Harpreet suggested a change in the map syntax which solved the problem.

Powered by Struct AI
5
14mo
Solved
Join the chat
Jul 11, 2022 (14 months ago)
Rude
Photo of md5-001a6b8b05601dc8ac56c5f364768cc1
Rude
03:36 PM
Hi, does anyone use typesense with flutter? Im trying to map a typesense document into a custom dart object like the following:
final hits = (a['hits'] as List)
                      .cast<Map>()
                      .map((e) => UserSearchable(name: e['document'] as Map['name'] as String, id:e['document'] as Map['id'] as String, imageUrls: e['document'] as Map['imageUrls'] as List<String>))
                      .toList();

but it throws an error saying "The argument type 'Map<dynamic, dynamic>' can't be assigned to the parameter type 'String'". Anyone deal with something similar?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
03:44 PM
CC: Harpreet
Harpreet
Photo of md5-745d880d794220d9f0fb9ade17c6b861
Harpreet
06:05 PM
Hi Rude
Is this causing the issue?
name: e['document'] as Map['name'] as String

if so, can you try
name: (e['document'] as Map)['name'] as String
06:15
Harpreet
06:15 PM
Otherwise doing
e['document']['name"]

should suffice
Jul 12, 2022 (14 months ago)
Rude
Photo of md5-001a6b8b05601dc8ac56c5f364768cc1
Rude
05:11 PM
Yup, looks like that worked! Thank you!