import 'dart:math';
void main() {
print(initSome());
}
initSome() {
var name = "hi";
var age = 18;
var hight = 1.70;
dynamic value = 18;
value = "1";
Object temp = "1";
print("$value");
print(value == temp);
var temp1;
print(temp1);
Person p = Person("ada");
p.name = "112";
print("${p.name}");
String str2 = """Hi,Bruce
12323
ooo
This is Xiaoming.
""";
var a = true;
var arr = ["1", "2", "3"];
var maps = {
"1": "1s",
"2": "1s",
"3": 1,
};
print(arr[1]);
print(maps["2"]);
print(maps.length);
print("\u{1f600}");
Runes input = new Runes("\u{1f600} \u{1f600} \u{1f600}");
print(String.fromCharCodes(input));
shoDesc("Bruce", (name) {
print("name = $name");
});
showDesc1("ada");
Wrold wrold = Wrold(name);
var names = wrold?.name; //先判斷p是否為null,如果是碟绑,則name為null撰豺;如果否颓屑,則返回p.name值
print(names);
var num = 10;
var resutlt = num ~/ 3; //得出一個小于等于(num/3)的最大整數(shù)
print(resutlt);
var name1;
var name2 = name1 ?? "123"; //如果name1不為null形纺,則name2值為name1的值,否則值為123
print(name2);
Banane(20, "red") //..的使用,級聯(lián)操作
..showWeight()
..showColor();
/**
* if and else
for循環(huán)
while和do-while循環(huán)
break和continue
switch-case語句
*/
if (num == 10) {
print("1");
} else {
print("0");
}
for (var i = 0; i < 10; i++) {
print(i);
}
try {
testException();
} catch (e) {
print(e);
}
//類
Tree t = Tree.init();
Tree t1 = new Tree("test111");
print(t.desc);
print(t1.desc);
Apple();
Apple.desc("say hello");
Apple1 atemp = Apple1();
atemp.log(); ////可執(zhí)行從LogUtil繼承過來的方法
//===================
//泛型
FruitFactory<Banana> f = FruitFactory();
Banana ab = f.produceFutit(Banana("a banana"));
ab.log();
FruitFactory<Bjc> f1 = FruitFactory();
Bjc abc = f1.produceFutit(Bjc("a bjc"));
abc.log();
return "1";
}
void shoDesc(var name, Function age) {
age(name);
}
class Person {
static const desc = "23";
var name;
Person(this.name);
}
String getname() {
return "1";
}
void showDesc1(var name) {
print("that is a nested function!");
void println(var name) {
print("name=$name");
}
print(name == "ada" ? "ada1" : "fial");
println(name);
}
class Wrold {
var name = "1";
Wrold(this.name);
}
//as的使用,as用來做類型轉化
//判斷對象是否為XX類 b is Apple
class Banane {
var weight;
var color;
Banane(this.weight, this.color);
void showWeight() {
print("weight=$weight");
}
void showColor() {
print("color=$color");
}
}
void testException() => throw "exception";
class Tree {
var desc;
Tree.init() {
desc = "this is a seed";
}
Tree(var des) : desc = des;
}
class Fruit {
Fruit() {
print("this is fruit");
}
Fruit.desc(var desc) {
print("$desc");
}
}
class Apple extends Fruit {
Apple() : super() {
print("is it");
}
Apple.desc(var desc) {
print("$desc");
}
}
class LogUtils {
void log() {
print("this is a log");
}
}
class Fruit1 {
Fruit1() {
print("this is furit1");
}
}
class Apple1 extends Fruit1 with LogUtils {
Apple1() : super() {
print("this is apple");
}
}
class Bjc {
var desc;
Bjc(this.desc);
void log() {
print("${this.desc}");
}
}
class Banana {
var desc;
Banana(this.desc);
void log() {
print("${this.desc}");
}
}
class FruitFactory<T> {
T produceFutit(T t) {
return t;
}
}
Dart語法記錄
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來芦缰,“玉大人企巢,你說我怎么就攤上這事∪美伲” “怎么了浪规?”我有些...
- 文/不壞的土叔 我叫張陵,是天一觀的道長探孝。 經(jīng)常有香客問我笋婿,道長,這世上最難降的妖魔是什么顿颅? 我笑而不...
- 正文 為了忘掉前任缸濒,我火速辦了婚禮,結果婚禮上粱腻,老公的妹妹穿的比我還像新娘庇配。我一直安慰自己,他們只是感情好绍些,可當我...
- 文/花漫 我一把揭開白布捞慌。 她就那樣靜靜地躺著,像睡著了一般柬批。 火紅的嫁衣襯著肌膚如雪啸澡。 梳的紋絲不亂的頭發(fā)上,一...
- 文/蒼蘭香墨 我猛地睜開眼冰更,長吁一口氣:“原來是場噩夢啊……” “哼产徊!你這毒婦竟也來了?” 一聲冷哼從身側響起蜀细,我...
- 正文 年R本政府宣布,位于F島的核電站矾踱,受9級特大地震影響恨狈,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜呛讲,卻給世界環(huán)境...
- 文/蒙蒙 一禾怠、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧圣蝎,春花似錦刃宵、人聲如沸。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至关面,卻和暖如春坦袍,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背等太。 一陣腳步聲響...
推薦閱讀更多精彩內(nèi)容
- 最近在接觸flutter這個框架娩嚼,從中了解到它開發(fā)的依賴語言是Dart,工欲善其事必先利其器滴肿,想用flutter岳悟,...
- 參考《Flutter實戰(zhàn)》 獨特語法: 1、可選命名參數(shù) 2泼差、..(級聯(lián)操作符) 3贵少、?.(條件成員訪問運算符) ...
- 表結構 要求:請用一條sql語句統(tǒng)計出下面結果(優(yōu)秀條件不低于80分) SQL語句: SELECT `type`,...
- 簡介: 學習東西套啤,一定要養(yǎng)成知識整理的習慣宽气。再簡單的知識,堆積多了潜沦,也可能會忘記。今天給大家推薦一個標記語言Mar...