dropRightWhile method
starts removing elements
from the ending of list
until condition becomes false
var list = <int>[2, 1, 3, 4, 5];
list.dropRightWhile((element) => element >= 3); // list = [2, 1];
Implementation
List<T?> dropRightWhile(bool Function(T? element) test) {
var index = length - 1;
while (index >= 0) {
if (!test(this[index])) {
break;
}
removeLast();
index--;
}
return this;
}