'How to pass multiple Text structures through 'ListView.builder'

I have a ShowDialog function, gained through an SDK that allows Text/ String entries to be passed through a structure that ends up with them populating a map marker, a pop up with metadata.

I wanted to be able to split the list and edit the style of the text

For example,

    "Last seen: $recordedattime"

Last seen: would be a different fontWeight to $recordedattime

I received working code for this, but it wouldnt function as the ShowDialog function is used to pass all the various metadata pop ups to their map marker.

These are different List's and some are just Strings

This means that this method won't work as there isnt always a List split by :

NewTextWidget({required String message, Key? key})
      : prefix = message.split(": ")[0],
        value = message.split(": ")[1],
        super(key: key);

Any ideas on how I can pass different structures through Listview.Builder, editing the text to different styles depending on whether it is a List or String?

Full class for Text Stlye assuming it is a List Last seen: $recordedattime style, not just a String for example

class NewTextWidget extends StatelessWidget {
  final String prefix;
  final String value;

  NewTextWidget({required String message, Key? key})
      : prefix = message.split(": ")[0],
        value = message.split(": ")[1],
        super(key: key);

  @override
  Widget build(BuildContext context) {
    return RichText(
      text: TextSpan(
          text: prefix,
          style: const TextStyle(
            fontWeight: FontWeight.w600),
          children: [
            TextSpan(
                text: value,
                style: const TextStyle(
                  fontWeight: FontWeight.w400))
          ]),
    );
  }
}

ShowDialog (where ListBody communicates with the above function to style it)

Future<void> _showDialog(String titlee, String message) async {
    return showDialog<void>(
      context: context,
      barrierDismissible: false,
      builder: (BuildContext context) {
        return AlertDialog(
          backgroundColor: Color(0xff2AC6FF),
          shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(10)),
          title: Text(titlee),
          content: SingleChildScrollView(
            child: 
          ListBody(children: [NewTextWidget(message: message)])
          ),
          actions: <Widget>[
            TextButton(
              child: Text('OK',
...

Thank you



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source