Flutter Extending HashMap

Viewed 692

I am developing a Flutter application, and i am triying to do this

abstract class DataObject extends HashMap<String, dynamic> {
//.....
}

but no matter what i try i keep getting this error.

error: The generative constructor 'HashMap<K, V> HashMap({bool Function(K, K) equals, int Function(K) hashCode, bool Function(dynamic) isValidKey})' expected, but factory found. (non_generative_constructor at .....)

This used to work when i did it in java but now in Dart i cannot get it to work.

Any help?

To clarify what i am trying to accomplish, i am planing to create a Class where all my DataObject extend from, to try and represent a record using a key value pair. And implement a group of functions that can be used on the data.

1 Answers

Hi i finally was able to get what i wanted to do.

Here is the way i was able to get it done.

abstract class ADataObject extends HashMap <String, dynamic> {
//

  factory ADataObject() => HashMap.identity();

//
}

this way i was able to extend hashmap and Create my own map with my own types, and my own methods to manipulate the data.

Related