你能给我一些关于在 Dart 中为 List 对象创建动态索引扩展的建议吗
以下是我的意思:
final List<String> myList = ['one', 'two', 'three'];
// by default, get an value at [index] belike:
myList[1];
// but what I want to implement belike:
myList.1;
myList.0;
myList.2;
myList.5; // ==> will throw exception
也许它们看起来很愚蠢,但对我来说,它是如此酷和奇特的编码风格
感谢您的帮助和建议
import 'package:amra/amra.dart' as amra;
void main(List<String> arguments) {
MyList._0;
MyList._1;
MyList._2;
}
class MyList{
static List<String> myList = ['one', 'two', 'three'];
static String _0(){
return MyList.myList[0];
}
static String _1(){
return MyList.myList[1];
}
static String _2(){
return MyList.myList[2];
}
}