티스토리 뷰

 

| Datatype

 

| List / collection if

-Collection if ) List 생성 시, 조건에 따라  element(속성) 추가 ex) 로그인 여부에 따라 다른 버튼 노

//List
void main() {
  var numbers = {1, 2, 3, 4, 5};
  var giveMeFive = true;
  List<int> num = [1, 2, 3,
    if(giveMeFive) 5, //collection if : giveMeFive true면 5 추가
  ];
//collection if를 안 쓰면,  
  if(giveMeFive){
    num.add(5);
  }
  print(num);  // [1, 2, 3, 5]
}

| String Interpolation

//text에 변수 추가
void main() {
  var name ='nico';
  var age = 20;
  var greeting = "Hello everyone, my name is $name, nice to meet you and I'm ${age + 2}";
  print(greeting); //Hello everyone, my name is nico, nice to meet you and I'm 22
}

 

| collection for

//navigation bar, user  
void main() {
  var oldFriends = ['abc', 'bcd'];
  var newFriends = ['cde', 'def',
      for(var friend in oldFriends)"❤️$friend"];
  
  print(newFriends); //[cde, def, ❤️abc, ❤️bcd]
}

// collection if, collection for : UI
// user 로그인에 따라 버튼 노출 등 사용시 코드 축약!

 

| Maps / Sets

//python dictionary유사
void main() {
  var player = {
    'name':'son',
    'team' : 'totnam',
    'position':'striker'
  };//object, 타임스크립트 any
  
  Map<int, bool>player2 = {
    1:true,
    2:false,
    3:true
  };
  
  Map<List<int>, bool> player3 ={
    [1,2,3,4]:true,
  };
  
  List<Map<String, Object>> p = [
    {'name':'son', 'xp':199993.999},
    {'name':'son', 'xp':199993.999}
  ];
}
// set : sequence(순서), unique element //element not unique : List
//python tuple

void main() {
  var num = {1,2,3,4}; //set
  Set<int> num1 = {9,8,7};
  num1.add(6);
  num1.add(7);
  print(num1); //{9, 8, 7, 6}
}

'TOTAL > Flutter & Dart' 카테고리의 다른 글

[Dart]_total  (0) 2023.01.08
[Dart_01]변수  (0) 2023.01.08
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2026/02   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
글 보관함