on Saturday, 18th of July, 2020

String is the basic class with which you write text.

String greeting = 'hello, world';
String confirm = 'Press to Confirm';
String userName = 'WallaceTheCat';

Strings can be concatenated with + operator, or by simply placing multiple strings next to eachother:

print("Hello," + " World");
// Hello, World

print ("Hello" "," " World");
// Hello, World

You can interpolate values into strings with the $ operator for single values, and ${} for expressions.

var age = 29;
print("My age is $age");
// My age is 29

print("Next year I'll be ${age + 1}");
// Next year I'll be 30

The String class includes a number of methods you can use to manipulate the text.

String greeting = 'howdy'

// ['h', 'o', 'w', 'd', 'y']

assert(greeting.length == 5) // true

// 2

// false

Join thousands of Flutter developers.

Sign up for infrequent updates about Flutter and Dart.

You can get all this content and more in one place. Check out my new book Flutter in Action