Skip to content

Instantly share code, notes, and snippets.

@doyle-flutter
Created February 15, 2021 01:31
Show Gist options
  • Save doyle-flutter/8d1f95d8c52ae55cbe20db7f940b3f5f to your computer and use it in GitHub Desktop.
Save doyle-flutter/8d1f95d8c52ae55cbe20db7f940b3f5f to your computer and use it in GitHub Desktop.
static Future<void> doRender({required HttpRequest req, required HttpResponse res, required String path, Map<String, String>? data}) async {
final File _file = File(path);
final String _readData = await _file.readAsString();
String _result = _readData;
if (data != null) {
data.keys.toList().forEach((String key) {
_result = _result.replaceAll("<do>$key</do>", data[key].toString());
_result = _result.replaceAll("<do> $key </do>", data[key].toString());
});
}
res.headers.contentType = ContentType.html;
res.write(_result);
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment