Flutterの基本データ型テスト


1、Flutterのデータ基本タイプ


Dart言語はすべてオブジェクトなので、初期化されていない場合はnullがデフォルトです.
  • Number(int、doubkle)
  • String
  • Boolean(bool) 
  • List 
  • Map

  •  
     
     
     
     
     
     

    2、テストコード

     void testData() {
    
        //Number int double
        int a = 4;
        int b = 8;
        print(a + b);
        int a1;
        if (a == null) {
          print('a == null');
        } else {
          print('a != null');
        }
    
        if (a1 == null) {
          print('a1 == null');
        } else {
          print('a1 != null');
        }
    
        double c = 5.9;
        double d = 6.4;
        print(c + d);
    
        //String 
        var chen = 'chen';
        var yu = 'yu';
        var name = chen + yu;
        print(name);
    
        var hello = '''
        hello word
        public static void main1
        ''';
        print(hello);
    
        var word = """
        hello word
        public stati void main2
        """;
        print(word);
    
    
        //Boolean 
        bool isSelect = false;
        if (isSelect) {
          print('isSelect is true');
        } else {
          print('isSelect is false');
        }
    
    
        //List 
        var list = [];
        list.add(1);
        list.add(2);
        print(list);
        print('size is ${list.length}');
    
        list.removeAt(0);
        print(list);
        print('size is ${list.length}');
    
    
        //Map 
        var week = {'one':'test1', 'two':'test2'};
        print(week);
        print('week length is ${week.length}');
        week.putIfAbsent('three', () => 'test3');
        print(week);
        print('week length is ${week.length}');
      }

     
     
     
     
     
     
     
     
     

    3、運行結果

    I/flutter (24359): 12
    I/flutter (24359): a != null
    I/flutter (24359): a1 == null
    I/flutter (24359): 12.3
    I/flutter (24359): chenyu
    I/flutter (24359):     hello word
    I/flutter (24359):     public static void main1
    I/flutter (24359):     
    I/flutter (24359):     hello word
    I/flutter (24359):     public stati void main2
    I/flutter (24359):     
    I/flutter (24359): isSelect is false
    I/flutter (24359): [1, 2]
    I/flutter (24359): size is 2
    I/flutter (24359): [2]
    I/flutter (24359): size is 1
    I/flutter (24359): {one: test1, two: test2}
    I/flutter (24359): week length is 2
    I/flutter (24359): {one: test1, two: test2, three: test3}
    I/flutter (24359): week length is 3