In Dart, we can define a simple Tuple with a max length of 2. When Tuples have a length of 2, I like to assign labels as key, value respectively. This is just experimental and a learning process for myself. To define a Tuple, it’s really simple. We will create an immutable class that can be assigned 2 types. A key and a value. This will have a max length of 2. @immutable
class Tuple<K, V> {
const Tuple(this.key, this.value);
final K key;
final V value;
}
void main() {
const myTuple = Tuple<String, int>('myKey', 1234);
}