Flutter Extending HashMap
626
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.
Author by
rread
Updated on December 23, 2022Comments
-
rread over 1 year
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.
-
rread over 3 yearsBut i have seen many uses of HashMap in Flutter? So why not use hashmap ?
-
Alok over 3 yearsThis will answer your question: stackoverflow.com/a/29338285/5362583
-
jamesdlin over 3 yearsIt likely would be easier to extend
DelegatingMap
frompackage:collection
instead and delegate to aHashMap
. -
rread over 3 yearsyou got a example of delegatingMap?
-