max method

Future<T> max(
  1. [Comparator<T>? comparator]
)

Converts a Stream into a Future that completes with the largest item emitted by the Stream.

This is similar to finding the max value in a list, but the values are asynchronous.

Example

final max = await Stream.fromIterable([1, 2, 3]).max();

print(max); // prints 3

Example with custom Comparator

final stream = Stream.fromIterable(['short', 'looooooong']);
final max = await stream.max((a, b) => a.length - b.length);

print(max); // prints 'looooooong'

Implementation

Future<T> max([Comparator<T>? comparator]) => minMax(this, false, comparator);