728x90
[[1,2,3], [4,5,6], [7,8,9]] 를 [1,2,3,4,5,6,7,8,9] 로 바꾸어 줌.
https://sunnybong.tistory.com/256
[다트] 리스트 합치기
리스트를 합치는 일. 과연 많이쓸까? 그냥 코드 문법만 공부하면, 익숙해지기 어렵지만 플러터에서는 꼭 필요한 기능이다ㅋ 예를 들어... 다른 함수에서 받아온 두개의 위젯 리스트를 하나의 컬
sunnybong.tistory.com
void main() {
var list1 = [1,2,3,4];
var list2 = [5,6,7,8];
var list3 = [9,10,11,12];
// #1 addAll
var newlist1 = List.from(list1)..addAll(list2);
print(newlist1);
// #2 expand
var newlist2 = [list1, list2].expand((x) => x).toList();
print(newlist2);
var newlist2_1 = [list1, list2, list3].expand((x) => x).toList();
print(newlist2_1);
// #3 after Dart 2.3 (...)
var newlist3 = [...list1, ...list2, ...list3];
print(newlist3);
}
https://www.educative.io/answers/how-to-combine-lists-using-the-expand-method-in-dart
How to combine lists using the expand() method in Dart
Contributor: Maria Elijah
www.educative.io
728x90
'개발 > Flutter' 카테고리의 다른 글
Mac flutter 2.5.3 version으로 돌리기 (0) | 2022.09.09 |
---|---|
flutter compileSdkVersion 33 안되는 문제 (0) | 2022.09.09 |
In flutter, Making 2 page with 1 GetXController (0) | 2022.09.06 |
Flutter에서 지네릭 메서드 만들기 (0) | 2022.09.02 |
static 변수만 사용하고 constructor 쓸 필요 없는 class (0) | 2022.09.01 |