I take the first 5 groups of data returned from the departures
API, using the class Boards
and put them into a List of returned parsed Json
.
var mappedList = boards.departures!.take(5).toList();
I then map it so it is a recurring list, and choose the data's I want.
var mappedValues = mappedList.map((m) => {
ListBody(
children: <Widget>[
RichText (
text: TextSpan(
children: <TextSpan> [
TextSpan(text: "\n\nDestination ",
style: TextStyle(
fontSize: 22 ,
fontWeight: FontWeight.w400,
color: Color(0xff2F2F2F),
)
),
TextSpan(text: m.transport!.headsign.toString(), style: TextStyle(
fontSize: 18 ,
fontWeight: FontWeight.w400,
color: Color(0xff2F2F2F),
fontFamily: 'DMSans'
)
),
TextSpan(text: "\n\nNo.",
style: TextStyle(
fontSize: 22 ,
fontWeight: FontWeight.w400,
color: Color(0xff2F2F2F),
)
),
TextSpan(text: m.transport!.name.toString(), style: TextStyle(
fontSize: 18 ,
fontWeight: FontWeight.w400,
color: Color(0xff2F2F2F),
fontFamily: 'DMSans'
)
),
]
)
)
])}).toList();
I then pass it to Metadata
Metadata metadata = new Metadata();
metadata.setCustomValue("ListBody", ListBodyMetadata(mappedValues));
mapMarker.metadata = metadata;
I have a Heading and then the data in each row.
I have tried different ways to use mapped data in a ListBody and I think this will work the best. I am just unable to pass it to Metadata as it is List<Set<ListBody>>
instead of just the ListBody
I need.
I have tried setting a Metadata class for List<Set<ListBody>>
but it doesn't work as anticipated. ListBody works well within my application, I just need this dataset to pass into Metadata as one.
Any tips appreciated on how to pass the data, thanks
CodePudding user response:
I thinks what you want is this?. Since then you have a ListBody with multiple text widgets instead of a list of ListBody( with 1 text widget)
var mappedValues = ListBody(
children: mappedList.map((m) => RichText ()).toList(),
);
example on how to use RichText:
RichText(
text: TextSpan(
children: <TextSpan>[
TextSpan(
text: 'Hi, ',
style: style.onBackground(context, opacity: .7)),
TextSpan(
text: username,
style: style.onBackground(context),
),
],
),
),
```