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.

Share:
626
rread
Author by

rread

Updated on December 23, 2022

Comments

  • rread
    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
      rread over 3 years
      But i have seen many uses of HashMap in Flutter? So why not use hashmap ?
    • Alok
      Alok over 3 years
      This will answer your question: stackoverflow.com/a/29338285/5362583
    • jamesdlin
      jamesdlin over 3 years
      It likely would be easier to extend DelegatingMap from package:collection instead and delegate to a HashMap.
    • rread
      rread over 3 years
      you got a example of delegatingMap?