i method

int i(
  1. String key, [
  2. int defaultValue = 0
])

获取 value 转 int

Implementation

int i(String key, [int defaultValue = 0]) {
  final value = this[key];
  if (value is int) return value;
  if (value is double) return value.toInt();
  if (value == null) {
    XLog.d('$key=null => int:$defaultValue');
    return defaultValue;
  }
  final other = int.tryParse(value.toString()) ?? defaultValue;
  XLog.d('${value.runtimeType} $key=$value => int:$other');
  return other;
}