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.isBlank) {
    return 0;
  }
  var words = this.trim().split(RegExp(r'(\s+)'));
  var magicalNumber = words.length / wordsPerMinute;
  return (magicalNumber * 100).toInt();
}