Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear a list in Dart?

Tags:

dart

There are two options over there to clear some list

List<String> foo = ['a', 'b'];
...
foo = [];
// vs
foo.clear();

What is the best option? And when to use these variants?

like image 430
rozerro Avatar asked Dec 31 '22 19:12

rozerro


1 Answers

.clear() will remove data from list with the same reference and foo = [] will have clear data with new reference

Note: .clear() is the best option

like image 177
Nooruddin Lakhani Avatar answered Feb 05 '23 04:02

Nooruddin Lakhani