From d6d12ab312be5c2953d189f99883cc7935d707cf Mon Sep 17 00:00:00 2001 From: FahadFahim71 <45163265+FahadFahim71@users.noreply.github.com> Date: Tue, 20 Feb 2024 16:27:44 +0100 Subject: [PATCH] feat(timeline-post-creation): add options to enforce image and content length --- .../lib/src/config/timeline_options.dart | 20 +++++++++++++++++++ .../timeline_post_creation_screen.dart | 19 ++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/packages/flutter_timeline_view/lib/src/config/timeline_options.dart b/packages/flutter_timeline_view/lib/src/config/timeline_options.dart index 18715b4..9222071 100644 --- a/packages/flutter_timeline_view/lib/src/config/timeline_options.dart +++ b/packages/flutter_timeline_view/lib/src/config/timeline_options.dart @@ -43,6 +43,11 @@ class TimelineOptions { this.postPadding = const EdgeInsets.all(12.0), this.filterOptions = const FilterOptions(), this.categoriesOptions = const CategoriesOptions(), + this.requireImageForPost = false, + this.minTitleLength, + this.maxTitleLength, + this.minContentLength, + this.maxContentLength, }); /// Theming options for the timeline @@ -121,6 +126,21 @@ class TimelineOptions { /// Options for using the category selector. 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 { diff --git a/packages/flutter_timeline_view/lib/src/screens/timeline_post_creation_screen.dart b/packages/flutter_timeline_view/lib/src/screens/timeline_post_creation_screen.dart index 2a7c409..d0452f6 100644 --- a/packages/flutter_timeline_view/lib/src/screens/timeline_post_creation_screen.dart +++ b/packages/flutter_timeline_view/lib/src/screens/timeline_post_creation_screen.dart @@ -64,6 +64,25 @@ class _TimelinePostCreationScreenState setState(() { editingDone = 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!; + } }); }