Flutter学习笔记(dart 语法篇)

//可空类型
int? aa = null;
//抽象类

abstract class DrinkWater {
void drink();
}
//别名
typedef AgeBlock(String name);
class Person {
String name = "";
String code = "";
Int _age = 0 //私有属性 当前文件可访问,是新建的文件就无法访问了
get age {
return _age;
}
late AgeBlock nameBlock; //延迟加载的可不让其初始化
Person(String name,String code){
this.name = name;
this.code = code;
}
//必须传参的
Person(requried String name,requried String code){
this.name = name;
this.code = code;
}
//命名构造函数
Person.loadinit(this.name,this.code);
//可选参数
fixSome(int a,[String age = "123"]) {
print('{age}');
}
//命名函数
fix1Some(int a,{String age = "123"}) {
print('{age}');
}
// 闭包
fuxa(AgeBlock ablock){
this.nameBlock = ablock;
this.nameBlock(name);
}
//私有方法
_foaj(){
void drink(){
print("hhha");
}
}
//继承
class Student extends Person{
String stuNube = "";
Student(name,code,String stuNube):super(name,code){
this.stuNube = stuNube;
}
@override
void drink(){
print("jan");
}
}

void main() {
var listsra = [1,2,3];
// listsra.forEach((value){
// print(value);
// });
//这种就不需要
// listsra.forEach((value) => {
// print(value)
// });
var newlist = listsra.map((va){
return va * 2;
});
print(newlist);
print(listsra.length);
var map = {"123":1,"sak":{"jj":"kk"}};
print(map);
listsra.add(4);
print(listsra.length);
Person p = Person("13","123");
print(p.name);
p.fix1Some(1,age:"1234");
p.fixSome(1);
p.fuxa((value){
print('{value}jjjaj');
});
//等价于 p.name = ""; p.code = ""; p.fuxa ---
Student stu = new Student("jj","jjja","19239");
print(stu.stuNube);
stu.drink();
//多态的表现
Person pp = stu;
pp.drink();

}
//多重继承 mix with 关键词
1.不能有构造函数 但是继承某个xxx就可以
2.复写问题 后面的会覆盖前面的如 AB都有谁在后就是谁
class A {
ppA(){

}
}
class B {
ppB(){

}
}
class C extends xxx with A,B {

}

//泛型
T getdata(T value){
return value;
}
getdata("asdasd");

//扩展
extension ppajjj on Person{
Function void mmmm(){
}
}

你可能感兴趣的:(Flutter学习笔记(dart 语法篇))