insert method

dynamic insert(
  1. int index,
  2. dynamic element
)

element 无论是 int 还是 double 返回 num 自己的类型 element 是String 返回 String 类型

Implementation

dynamic insert(int index, dynamic element) {
  if (element is! num && element is! String) return this;
  if (element is String) {
    return toString().insert(index, element);
  } else {
    final String data =
        toString().insert(index, (element as num).toInt().toString());
    if (this is int) return num.parse(data).toInt();
    if (this is double) return num.parse(data).toDouble();
  }
  return this;
}