Flutter之基本數(shù)據(jù)類型測試
1、Flutter的數(shù)據(jù)基本類型
Dart語言里一切皆為對象,所以如果沒有將變初始化,那么它的默認(rèn)值為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、運(yùn)行結(jié)果
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
作者:chen.yu
深信服三年半工作經(jīng)驗(yàn),目前就職游戲廠商,希望能和大家交流和學(xué)習(xí),
微信公眾號:編程入門到禿頭 或掃描下面二維碼
零基礎(chǔ)入門進(jìn)階人工智能(鏈接)