withBuffer<T> method
Runs an action using the provided buffer, restoring the previous buffer afterward.
Implementation
T withBuffer<T>(
Buffer newBuffer,
T Function() action, {
bool clearBuffer = true,
}) {
final previousBuffer = buffer;
final previousBlocks = List<Buffer>.from(_blockBuffers);
buffer = newBuffer;
_blockBuffers.clear();
try {
final result = action();
if (clearBuffer) {
buffer.clear();
}
return result;
} finally {
buffer = previousBuffer;
_blockBuffers
..clear()
..addAll(previousBlocks);
}
}