I need something like an abstract static method, but since we cannot do something like this in the dart, so I am looking for alternatives, my situation is like this:-
Firstly classes:-
abstract class Parent {
static String get name;
static Parent fromSecretText(String name);
}
class ChildFirst {
static String get name => 'first_child'; //note:- here it is not the typename
static ChildFirst fromSecretText(String name) {
// generate object
}
}
class ChildSecond {
static String get name => 'second_child';
static ChildSecond fromSecretText(String name) {
// generate object
}
}
Now I need methods like this:-
Future<List<T>> getMultiple<T extends Parent>() async {
final List<String> secretKeys = await getSecretKeys(T.name);
List<T> res = [];
for (var secretKey in secretKeys) res.add(T.fromSecretText(secretKey));
return res;
}
Aucun commentaire:
Enregistrer un commentaire