dart concatenate code example

Example 1: dart concatenate string

String a = 'a';
String b = 'b';

var c1 = a + b; 	// + operator
var c2 = '$a$b'; 	// string interpolation	(prefered method)
var c3 = 'a' 'b'; 	// string literals separated only by whitespace are concatenated
var c4 = 'abcdefgh abcdefgh abcdefgh abcdefgh' 
         'abcdefgh abcdefgh abcdefgh abcdefgh';

Example 2: concatenate in flutter

In dart there are many string options.

For concatenation, you can do :

    'hello $myVariable'
    "hello ${myVariable.myProperty}"
    'hello ' 'world' (only works with string literals)
    'hello' + myVariable

So in your case, you can do a print(" $str1 $str2")

Tags:

Dart Example