1、Flutter的数据基本类型
Dart语言里一切皆为对象,所以如果没有将变初始化,那么它的默认值为null
Number(int、doubkle)StringBoolean(bool)ListMap
2、测试代码
void testData() {//Number包含了int和doubleint 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 wordpublic static void main1''';print(hello);var word = """hello wordpublic 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): 12I/flutter (24359): a != nullI/flutter (24359): a1 == nullI/flutter (24359): 12.3I/flutter (24359): chenyuI/flutter (24359):hello wordI/flutter (24359):public static void main1I/flutter (24359):I/flutter (24359):hello wordI/flutter (24359):public stati void main2I/flutter (24359):I/flutter (24359): isSelect is falseI/flutter (24359): [1, 2]I/flutter (24359): size is 2I/flutter (24359): [2]I/flutter (24359): size is 1I/flutter (24359): {one: test1, two: test2}I/flutter (24359): week length is 2I/flutter (24359): {one: test1, two: test2, three: test3}I/flutter (24359): week length is 3
公众号:记得关注我。
如果觉得《Flutter之基本数据类型测试》对你有帮助,请点赞、收藏,并留下你的观点哦!