writeAndClose method
Writes the layout
to the response and closes it.
This method ensures the response is not written if it is already closed.
Implementation
Future writeAndClose(String layout) async {
if (isClosed) return;
layout = onClose(layout);
response.write(layout);
await _close();
}