stopwatchToSeconds method

String stopwatchToSeconds(
  1. Stopwatch stopwatch
)

Stop stopwatch and conditionally format elapsed time as seconds or ms

Implementation

String stopwatchToSeconds(Stopwatch stopwatch) {
  stopwatch.stop();
  final milliseconds = stopwatch.elapsedMilliseconds;

  if (milliseconds > 1000) {
    final roundedMilliseconds = (milliseconds / 1000).toStringAsFixed(2);
    return '${roundedMilliseconds}s';
  } else {
    return '${milliseconds}ms';
  }
}