I want to create a helper class that will extend only a class that is derived from an abstract class. I face the following problems.
i need derived class to provide value to static member of an abstract class and access that value to the helper class.
I need to create a fromMap static or factory constructor, the signature will be in the abstact but the implementation is from derived.
abstract class DatabaseModel { static String tableName; Map<String, dynamic> toMap(); factory DatabaseModel.fromMap(Map<String, dynamic> map) { throw UnimplementedError(); } } class DatabaseHelper<T extends DatabaseModel> { Future<List<T>> getAllItems() async { Database db = await openDatabase('database.db'); final List<Map<String, dynamic>> maps = await db.query(T.tableName); return List.generate(maps.length, (i) { return T.fromMap(maps[i]); }); } }
Here i got the following error:
- The method 'fromMap' isn't defined for the type 'Type'. Try correcting the name to the name of an existing method, or defining a method named 'fromMap'
- he getter 'tableName' isn't defined for the type 'Type'. Try importing the library that defines 'tableName', correcting the name to the name of an existing getter, or defining a getter or field named 'tableName'. Thanks in advance