get<T> static method

T get<T>(
  1. Map<String, dynamic> map,
  2. List<String> keys, {
  3. required T defaultValue,
})

Implementation

static T get<T>(
  Map<String, dynamic> map,
  List<String> keys, {
  required T defaultValue,
}) {
  dynamic current = map;
  for (var key in keys) {
    if (current is Map<String, dynamic> && current.containsKey(key)) {
      current = current[key];
    }
  }
  // string ကိုယူမှာ
  if (T == String && current is int) {
    current = current.toString();
  }
  if (T == String && current is double) {
    current = current.toString();
  }
  // int ကိုယူမှာ
  if (T == int && current is String) {
    if (int.tryParse(current) != null) {
      current = int.parse(current);
    }
  }
  // double ကိုယူမှာ
  if (T == double && current is String) {
    if (double.tryParse(current) != null) {
      current = double.parse(current);
    }
  }
  // custom type အတွက်မရေးထားဘူး

  return current is T ? current : defaultValue;
}