formatDistance function

String formatDistance(
  1. double distanceMetre, {
  2. String? suffix,
  3. String within1MetreText = "Right here",
})

Implementation

String formatDistance(double distanceMetre, {String? suffix, String within1MetreText = "Right here"}){
  final numberFormat = NumberFormat("#,###.#");
  if (distanceMetre < 1000) {
    if(distanceMetre <= 1){
      return within1MetreText ?? "Right here";
    }
    return numberFormat.format(distanceMetre) + "m" + (suffix != null ? " $suffix" : "");
  }
  return numberFormat.format(distanceMetre/1000) + "km" + (suffix != null ? " $suffix" : "");
}