Is there a way to create an empty string in Dart besides using "" or ''?

Viewed 1960

I'm looking for a safe and nice way, if any, to create an empty string in Dart that's not writing "" or ''.
For instance, lists have their own constructor List.empty(), but strings don't.
So, I'm asking if there is a better way than writing "" or '' to initialize an empty string.

2 Answers

There is no better way, as there is, many ways in creating empty strings

String str;
str = '';
str = "";
str = String.fromCharCodes([]);
str = 'a'.replaceFirst('a', '');

...

// and so it goes

And then you ask me "Which would you use?"

Of course I'll use the simple, elegant and old school way: ''

Happy coding :)

The only way is

String name="";

The other way would be

String? name;

but this will be null not empty

Related