Kev Channel
Kev Channel

Reputation: 13

How to split a string and output it in a row

Let's say I have this string "51-47-24" and I want to split the string .split("-") so that I can create this balls:

See image

How am I able to get that working? How can I show the splitted list in a row?

Upvotes: 1

Views: 246

Answers (2)

Jerome Escalante
Jerome Escalante

Reputation: 4387

You can try to use the Row widget.

String someString = "51-47-24";
List<String> someNumbers = someString.split("-");

...
    Row(
        children: someNumbers.map((someNum) =>
            Container(
               padding: EdgeInsets.all(5.0),
               child: Center(
                   child: Text("$someNum")
                   ),
               decoration: BoxDecoration(
                   color: Colors.yellow,
                   shape: BoxShape.circle
                   )
               )
           ).toList()
        )

Upvotes: 2

Richard Heap
Richard Heap

Reputation: 51682

      Center(
        child: Row(
          children: '51-47-24'
              .split('-')
              .map((s) => CircleAvatar(
                    child: Text(s),
                  ))
              .toList(),
        ),
      ),

Upvotes: 2

Related Questions