I want to implement https://pub.dev/packages/alphabet_scroll_view in my project.
I receive data from backend and I parse it to list, but when I want to give it to above package as list I am getting this error:
type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'String'
This how my list is looking after parsing it:
[
{
id: 1222,
hidden: 1,
nick_name: Saraya,
id_fb: ,
avatar: api/images/user/d4bfsd8769147.png,
city: Toruń, Polska
},
{
id: 2029,
hidden: 1,
etc.
}
and here is how I set it in my project:
AlphabetScrollView(
list: (snapshot.data! as List).map((e) => AlphaModel(e)).toList(),
selectedTextStyle: TextStyle(),
unselectedTextStyle: TextStyle(),
I am not good with these Lists and Maps and I don't have idea what I need to change to get rid of this error.
CodePudding user response:
The constructor of AlphaModel
expects a String
but you are giving it a Map
. Assuming you want to sort by nickname you can maybe do this instead:
list: (snapshot.data! as List).map((e) => AlphaModel(e['nick_name']).toList(),