Created
April 25, 2020 01:32
-
-
Save erluxman/98c2ab9d41fb2c20cc67c94956972721 to your computer and use it in GitHub Desktop.
Collection addition with Spread operator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
var numbers = [1, 2, 3]; | |
var names = ["Smith", "Laxman"]; | |
List<int> nullList; | |
List<int> getLostNumbers() => null; | |
//This is long way | |
print("\n\n\nLong Way"); | |
var list = List(); | |
list.addAll(numbers); | |
list.addAll(names); | |
//Hassale to add nullList | |
list.addAll(nullList??[]); | |
list.addAll(getLostNumbers()??[]); | |
list.forEach(print); | |
print("\n\n\nShort Way"); | |
//This is short way with easy null safe insertion | |
var list1 = [...numbers, ...names, ...?nullList, ...?getLostNumbers()]; | |
list1.forEach(print); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment