removeLast method
removes last item of the stack and if it's an instance of VoyagerStack
calls a VoyagerStackScope.onRemove
if it's registered
Implementation
VoyagerStack removeLast() {
if (_items.isEmpty) {
return this;
}
final stack = mutate((items) {
var lastItem = items.last;
final lastIndex = items.length - 1;
if (lastItem is VoyagerStack) {
lastItem = lastItem.removeLast();
if (lastItem.isEmpty) {
lastItem.onRemove();
items.removeLast();
} else {
items[lastIndex] = lastItem;
}
} else {
items.removeLast();
}
});
return stack;
}