Home > Back-end >  Flutter - Get String and Set Value
Flutter - Get String and Set Value

Time:11-15

I have the following code:

Text(welcome)

Where 'welcome' is a String from another page.

 String welcome = "Welcome"

Basic. But what I would like was to be able to request some value of this String for example the username that way when using the String 'welcome' I should pass the value 'username'.

It is possible?

CodePudding user response:

You can use string interpolation as follows:

Text("$welcome $username")

Where:

String welcome = "Welcome";
String username = "dnnx";

So the widget would say: "Welcome dnnx"

CodePudding user response:

Hm, I'm not sure... Are you asking about string concatenation? If so, you can do this by:

  1. Using plus operator:
  String welcome = 'Welcome';
  String userName = 'Tom';
  String space = ' ';
  
  String concatenated = welcome   space  userName;
  
  print(concatenated);
  1. By string interpolation:
  String welcome = 'Welcome';
  String userName = 'Tom';
  print ('$welcome $userName');
  • Related