test_demo.dart
void main(List<String> args) {
print('hello word sys');
const ls1 = [1, 2, 3, 4, 5];
//ls1[2] = 3; //const类型,理面的子数据不能修改,这样写直接报错
const ls2 = [1, 2, 3, 4, 5];
print(identical(ls1, ls2));
final ls3 = [1, 2, 3, 4, 5];
ls3[0] = 10;//final 类型理面的数据可以修改
print(ls3);
}
输出如下

class.dart
void main(List<String> args) {
var p = Person();
p.showInfo();
var cl1 = HttpClient();
var cl2 =HttpClient();
print(identical(cl1,cl2));
var req = Request('http://www.baidu.com','post');
req.showInfo();
}
abstract class Animal{
void say();
}
class PersonInfo{
void showInfo(){
print('this is show person info');
}
}
class Person extends Animal with PersonInfo{
@override
void say() {
// TODO: implement say
print('people say');
}
}
//单例
class HttpClient{
static final HttpClient _client = HttpClient._internal();
HttpClient._internal(){
}
factory HttpClient(){
return _client;
}
}
/// 可选类型
class Request {
String method;
String url;
Map<String,dynamic> params;
Request(this.url,[this.method='get',this.params]) {
this.params = {};
}
void showInfo() {
print('method $method --> url = $url --> params = $params');
}
}
输出如下:
this is show person info
true
method post --> url = http://www.baidu.com --> params = {}
本文深入探讨了Dart语言的特性,包括常量与最终变量的使用区别,类的继承与抽象类的实现,以及单例模式的应用。同时,通过实例展示了HTTP请求的构造与处理方式。
571

被折叠的 条评论
为什么被折叠?



