feat(timeline-post-creation): add options to enforce image and content length

This commit is contained in:
FahadFahim71 2024-02-20 16:27:44 +01:00
parent c5c394348e
commit d6d12ab312
2 changed files with 39 additions and 0 deletions

View file

@ -43,6 +43,11 @@ class TimelineOptions {
this.postPadding = const EdgeInsets.all(12.0), this.postPadding = const EdgeInsets.all(12.0),
this.filterOptions = const FilterOptions(), this.filterOptions = const FilterOptions(),
this.categoriesOptions = const CategoriesOptions(), this.categoriesOptions = const CategoriesOptions(),
this.requireImageForPost = false,
this.minTitleLength,
this.maxTitleLength,
this.minContentLength,
this.maxContentLength,
}); });
/// Theming options for the timeline /// Theming options for the timeline
@ -121,6 +126,21 @@ class TimelineOptions {
/// Options for using the category selector. /// Options for using the category selector.
final CategoriesOptions categoriesOptions; final CategoriesOptions categoriesOptions;
/// Require image for post
final bool requireImageForPost;
/// Minimum length of the title
final int? minTitleLength;
/// Maximum length of the title
final int? maxTitleLength;
/// Minimum length of the post content
final int? minContentLength;
/// Maximum length of the post content
final int? maxContentLength;
} }
class CategoriesOptions { class CategoriesOptions {

View file

@ -64,6 +64,25 @@ class _TimelinePostCreationScreenState
setState(() { setState(() {
editingDone = editingDone =
titleController.text.isNotEmpty && contentController.text.isNotEmpty; titleController.text.isNotEmpty && contentController.text.isNotEmpty;
if (widget.options.requireImageForPost) {
editingDone = editingDone && image != null;
}
if (widget.options.minTitleLength != null) {
editingDone = editingDone &&
titleController.text.length >= widget.options.minTitleLength!;
}
if (widget.options.maxTitleLength != null) {
editingDone = editingDone &&
titleController.text.length <= widget.options.maxTitleLength!;
}
if (widget.options.minContentLength != null) {
editingDone = editingDone &&
contentController.text.length >= widget.options.minContentLength!;
}
if (widget.options.maxContentLength != null) {
editingDone = editingDone &&
contentController.text.length <= widget.options.maxContentLength!;
}
}); });
} }