renderTag method
Renders a Tag object to HTML and sends it in the response.
You can use this method to render any HTML tag or widget that implements the Tag interface.
This method converts the Tag to an HTML string and then calls renderView to handle the response.
status
- The HTTP status code to be used. Default is 200.
toData
- A flag indicating whether to render the data as a parameter. Default is false.
data
- A map of parameters to be passed to the template. Default is an empty map.
pretty
- A flag indicating whether to pretty-print the HTML output. Default is false.
Returns a Future<String> containing the rendered HTML string.
Implementation
Future<String> renderTag({
required Tag tag,
int status = 200,
bool toData = false,
Map<String, dynamic> data = const {},
bool pretty = false,
}) async {
var htmlString = tag.toHtml();
htmlString = await renderView(
path: htmlString,
isFile: false,
status: status,
toData: toData,
data: data,
writeAndClose: false,
);
if (pretty) {
htmlString = HtmlFormatter.format(htmlString, indent: '\t');
}
await writeAndClose(htmlString);
return htmlString;
}