readTime method

int? readTime({
  1. int wordsPerMinute = 200,
})

Returns the average read time duration of the given String in seconds.

The default calculation is based on 200 words per minute.

You can pass the wordsPerMinute parameter for different read speeds.

Example

String foo =  'Hello dear friend how you doing ?';
int readTime = foo.readTime(); // returns 3 seconds.

Implementation

int? readTime({int wordsPerMinute = 200}) {
  if (this == null) return null;
  if (this!.isEmpty) return 0;
  final words = this!.trim().split(RegExp(r'(\s+)'));
  final magicalNumber = words.length / wordsPerMinute;
  return (magicalNumber * 100).toInt();
}