打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
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

 

公众号:记得关注我。

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
Flutter Map 常用操作方法概述
dart使用技巧集合
TypeScript数据类型
软件调试
java中数组的定义及使用
从零学习php之php数据类型/echo/print
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服