whenDouble<T> function

T? whenDouble<T>(
  1. double value,
  2. Map<double, ValueGetter<T>> conditionMap
)

English: Used to replace the switch method, because in some scenarios, an error warning of Case expressions must be constant;
If there is value in Map.keys of conditionMap, execute its corresponding ValueGetter method

中文: 用于取代switch方法,因为有些场景使用switch会出现Case expressions must be constant.的错误警告;
如果conditionMapMap.keys中有value的话,执行其对应的ValueGetter方法

example:

String? status = whenDouble<String>(2.0, {
  0.1: () {
    return "good";
  },
  1.0 + 1: () {
    return "nice";
  },
  double.parse("3.2"): () {
    return "better";
  },
});

Implementation

T? whenDouble<T>(double value, Map<double, ValueGetter<T>> conditionMap) {
  return conditionMap[value]?.call();
}