mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 08:15:16 +00:00
Can create surveys
This commit is contained in:
@ -5,6 +5,7 @@ import 'package:comunic/enums/post_target.dart';
|
||||
import 'package:comunic/enums/post_visibility_level.dart';
|
||||
import 'package:comunic/helpers/posts_helper.dart';
|
||||
import 'package:comunic/models/new_post.dart';
|
||||
import 'package:comunic/ui/dialogs/new_survey_dialog.dart';
|
||||
import 'package:comunic/utils/files_utils.dart';
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
import 'package:comunic/utils/post_utils.dart';
|
||||
@ -50,6 +51,7 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
|
||||
File _postImage;
|
||||
List<int> _postPDF;
|
||||
DateTime _timeEnd;
|
||||
NewSurvey _postSurvey;
|
||||
|
||||
bool get hasImage => _postImage != null;
|
||||
|
||||
@ -57,6 +59,8 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
|
||||
|
||||
bool get hasTimeEnd => _timeEnd != null;
|
||||
|
||||
bool get hasSurvey => _postSurvey != null;
|
||||
|
||||
bool get canSubmitForm =>
|
||||
!_isCreating && _postTextController.text.length > 5 ||
|
||||
postKind != PostKind.TEXT;
|
||||
@ -68,6 +72,8 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
|
||||
return PostKind.PDF;
|
||||
else if (hasTimeEnd)
|
||||
return PostKind.COUNTDOWN;
|
||||
else if (hasSurvey)
|
||||
return PostKind.SURVEY;
|
||||
else
|
||||
return PostKind.TEXT;
|
||||
}
|
||||
@ -132,6 +138,13 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
|
||||
selected: postKind == PostKind.COUNTDOWN,
|
||||
onTap: _pickCountdownTime,
|
||||
),
|
||||
|
||||
// Add survey
|
||||
_PostOptionWidget(
|
||||
icon: Icons.insert_chart,
|
||||
selected: postKind == PostKind.SURVEY,
|
||||
onTap: _pickSurvey,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@ -192,6 +205,7 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
|
||||
_postImage = null;
|
||||
_postPDF = null;
|
||||
_timeEnd = null;
|
||||
_postSurvey = null;
|
||||
});
|
||||
}
|
||||
|
||||
@ -262,6 +276,19 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
|
||||
});
|
||||
}
|
||||
|
||||
/// Pick a new survey for this post
|
||||
Future<void> _pickSurvey() async {
|
||||
final newSurvey =
|
||||
await showNewSurveyDialog(context: context, initialSurvey: _postSurvey);
|
||||
|
||||
if (newSurvey == null) return;
|
||||
|
||||
_resetPostSelection();
|
||||
setState(() {
|
||||
_postSurvey = newSurvey;
|
||||
});
|
||||
}
|
||||
|
||||
/// Submit new post
|
||||
Future<void> _submitForm() async {
|
||||
if (!canSubmitForm)
|
||||
@ -271,15 +298,15 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
|
||||
|
||||
try {
|
||||
await _postHelper.createPost(NewPost(
|
||||
target: widget.postTarget,
|
||||
targetID: widget.targetID,
|
||||
visibility: _postVisibilityLevel,
|
||||
content: _postTextController.text,
|
||||
kind: postKind,
|
||||
image: _postImage,
|
||||
pdf: _postPDF,
|
||||
timeEnd: _timeEnd,
|
||||
));
|
||||
target: widget.postTarget,
|
||||
targetID: widget.targetID,
|
||||
visibility: _postVisibilityLevel,
|
||||
content: _postTextController.text,
|
||||
kind: postKind,
|
||||
image: _postImage,
|
||||
pdf: _postPDF,
|
||||
timeEnd: _timeEnd,
|
||||
survey: _postSurvey));
|
||||
setState(() => _isCreating = false);
|
||||
|
||||
showSimpleSnack(context, tr("The post has been successfully created!"));
|
||||
|
Reference in New Issue
Block a user