'How to assign memory to a var in Dart

I'm making an app with Flutter that will, eventually, have to deal with rather large dictionaries (~5500 entries). The data for the dictionary is generated dynamically (basically a function that hashes the entries of another dictionaries into a single byte).

I will end up with a hashing dict that has a key of exactly 10 bytes and a value of exactly a single byte:

{"ABCDEFGHIJ": 0, "KLMNOPQRST": 1, ... }

I believe Dart is a dynamically typed language so in debugging mode I tried to look up how an existing dict was created. Visual studio has a functionality called "Run and debug" for this. Under there is a tab called "Variables". However, it only shows that the dict was declared as a map. So I tried experimenting myself. I have declared the map globally as follows:

var hashes = Map<String, Uint8>;

There are still a few problems with this method. Upon declaring the variable, I don't know yet how big it is going to be. Also, I don't know how to set a fixed string length up front.

Say that I have 10 values to hash at a given point. I want to dynamically assign the space for 10 <String, Uint8> entries at ONCE and then assign each key/value pair.

Is this doable? And if so, how?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source