createView function
Implementation
Future<void> createView(String name,
{String withArgument = '', String onCommand = ''}) async {
var sample = GetViewSample(
'',
'${name.pascalCase}View',
'',
'',
PubspecUtils.isServerProject,
);
if (withArgument.isNotEmpty) {
if (isURL(withArgument)) {
var res = await get(Uri.parse(withArgument));
if (res.statusCode == 200) {
var content = res.body;
sample.customContent = replaceVars(content, name);
} else {
throw CliException(
LocaleKeys.error_failed_to_connect.trArgs([withArgument]));
}
} else {
var file = File(withArgument);
if (file.existsSync()) {
var content = file.readAsStringSync();
sample.customContent = replaceVars(content, name);
} else {
throw CliException(
LocaleKeys.error_no_valid_file_or_url.trArgs([withArgument]));
}
}
}
handleFileCreate(name, 'view', onCommand, true, sample, 'views');
}