How to implement map of dynamic indices in dart (or of different execution)

I am working on an app in flutter but I don’t think the solution to this problem is only for dart but all the similar languages (python, js, even java, etc.), so don’t feel frightened to answer if you don’t know “dart”.

What I am trying to do:

  • Map<date, something>

    -> I want to have indexed dates so that I could:

mymap[date0] -> something0

and (most importantly)

mymap.of(index0) -> date0, something0

Problem: I want to have existing gaps so that there don’t have to be entries for every date between for example 14th March and 10th May.

mymap = {
 index 0: date 14.3.2023: something0,
 index 56: date 10.5.2023: something56
}

For that to work as I intend, there is a need for these features:

  • If there is an existing entry date0 and a new date is added that comes before date0:

    -> every other index needs to increase by the difference between date0new and date0old

mymap.add(date 12.3.2023, somethingNew)
-> {
 index 0: date 12.3.2023, somethingNew,
 index 2: date 14.3.2023: something0,
 index 58: date 10.5.2023: something56
}

Any solution can even include two maps, pointer, lists or anything that isn’t too inefficient because I could work around this if I didn’t want my code to work efficient.