Concatenate Listview into Flutter

Asked

Viewed 213 times

1

I’m trying to display a received list on Json, but I need to concatenate it for better visualization...

First case - No concatenation

Text(promocoes[index].descrprod)

Second case - With concatenation

Text('cód : $promocoes[index].codprod' )

In the second case returns me the following

Instance Of

What is the correct way to concatenate a text?

2 answers

1


To concatenate a "simple" variable we do as follows:

String nome = "Matheus";
String meuTexto = "Meu nome é $nome";

To concatenate properties of a class for example, we do it as follows

class NomeCompleto{
  String nome = "Matheus";
  String sobrenome = "Ribeiro";
}

NomeCompleto meuNomeCompleto = NomeCompleto();
String meuTexto = "Meu nome é ${meuNomeCompleto.nome}";
  • Thank you very much for your help...

  • @Juliano for nothing :P Just don’t forget to mark any of the answers as accepted little guy!

1

This question is practically the same as yours, basically you should use the { key so that the compiler can identify what you really want.

In your case I’d be:

Text('cód : ${promocoes[index].codprod}')

Browser other questions tagged

You are not signed in. Login or sign up in order to post.