save method
Implementation
Future<bool> save() async {
final UBlogResponse? b = editing;
final List<String> categoryIds = selectedCategories.map((UCategoryResponse cat) => cat.id).toList();
final Object? ok = await send(
b == null
? UServices.blog.create(
p: UBlogCreateParams(
tags: <int>[TagBlog.draft.number],
title: titleController.text,
subtitle: subtitleController.text.nullIfEmpty(),
slug: slugController.text.nullIfEmpty(),
content: contentController.text.nullIfEmpty(),
categories: categoryIds,
),
)
: UServices.blog.update(
p: UBlogUpdateParams(
id: b.id,
title: titleController.text,
subtitle: subtitleController.text.nullIfEmpty(),
slug: slugController.text.nullIfEmpty(),
content: contentController.text.nullIfEmpty(),
categories: categoryIds,
),
),
null,
);
if (ok == null) return false;
final String? id = b?.id ?? (ok as UResponse<String>).result;
if (id != null) {
for (final UFileData file in files) {
await UServices.media.create(
p: UMediaCreateParams(file: file, blogId: id, tag1: TagMedia.image.number),
onOk: (_) {},
onError: (_) {},
onException: (_) {},
);
}
}
unawaited(read());
return true;
}