使用时,代码提示会有删除线,但能正常使用:
void main() {
Mobile mobile = Mobile();
// ignore: deprecated_member_use_from_same_package
mobile.netWork2G();
}
class Mobile {
@deprecated
void netWork2G() {
print('手机使用2G网络');
}
void netWork3G() {
print('手机使用3G网络');
}
void netWork4G() {
print('手机使用4G网络');
}
void netWork5G() {
print('手机使用5G网络');
}
}

二、@override 重写
重写父类方法:
class Animal {
void eat() {
print('动物吃东西');
}
}
class Human extends Animal {
void say() {
print('人类会说话');
}
//利用元数据override重写父类方法
@override
void eat() {
print('人类会吃饭');
}
}
三、@proxy 代理四、@required 参数必传
MyHomePage({Key key, @required this.title}) : super(key:key);
五、自定义元数据custom_metadata_todo.dart文件
//自定义元数据@todo
library todo; //library封装了个todo的库
class Todo {
final String name;
final String content;
//和普通实例化类,不一样,前面多了个const
const Todo(this.name, this.content);
}
main.dart文件
import 'custom_metadata_todo.dart';
void main() {
Test test = Test();
}
class Test {
@Todo('张三', '做什么事')
void doSomeThing() {
print('do something');
}
}
