正常写法
enum Router {
home,
home2;
String get path => switch (this) {
Router.home => '/home',
Router.home2 => '/home2',
};
}
使用
print(Router.home.path);
新发现的写法
enum Router {
home('/home', name: ' 1'),
home2('/home2', name: ' 2'),
;
final String path;
final String name;
const Router(
this.path, {
required this.name,
});
}
使用
print(Router.home.path);
print(Router.home.name);