popOrNull method

E? popOrNull()

Removes and returns the top element of the stack.

Returns null if the stack is empty.

Example:

final stack = LinkedStack<int>();
print(stack.popOrNull()); // null
stack.push(42);
print(stack.popOrNull()); // 42

Implementation

E? popOrNull() {
  if (_top == null) {
    return null;
  }
  return pop();
}