diff --git a/lib/helpers/posts_helper.dart b/lib/helpers/posts_helper.dart index 9b4bfd4..ceb0a10 100644 --- a/lib/helpers/posts_helper.dart +++ b/lib/helpers/posts_helper.dart @@ -165,6 +165,7 @@ class PostsHelper { case PostKind.SURVEY: request.addString("question", post.survey.question); request.addString("answers", post.survey.answers.join("<>")); + request.addBool("allowNewAnswers", post.survey.allowNewChoicesCreation); break; case PostKind.YOUTUBE: diff --git a/lib/models/new_post.dart b/lib/models/new_post.dart index 0799b29..7a5236a 100644 --- a/lib/models/new_post.dart +++ b/lib/models/new_post.dart @@ -12,12 +12,15 @@ import 'package:meta/meta.dart'; class NewSurvey { final String question; final Set answers; + final bool allowNewChoicesCreation; const NewSurvey({ @required this.question, @required this.answers, + @required this.allowNewChoicesCreation, }) : assert(question != null), - assert(answers.length > 1); + assert(answers.length > 1), + assert(allowNewChoicesCreation != null); } class NewPost { diff --git a/lib/ui/dialogs/new_survey_dialog.dart b/lib/ui/dialogs/new_survey_dialog.dart index 9c746b9..8a6fbae 100644 --- a/lib/ui/dialogs/new_survey_dialog.dart +++ b/lib/ui/dialogs/new_survey_dialog.dart @@ -29,12 +29,15 @@ class __SurveyDialogState extends State<_SurveyDialog> { TextEditingController _questionController; final _choiceController = TextEditingController(); var _choices = Set(); + var _allowNewChoices = false; bool get canConfirm => _questionController.text.length > 2 && _choices.length > 1; - NewSurvey get newSurvey => - NewSurvey(question: _questionController.text, answers: _choices); + NewSurvey get newSurvey => NewSurvey( + question: _questionController.text, + answers: _choices, + allowNewChoicesCreation: _allowNewChoices); @override void initState() { @@ -42,7 +45,10 @@ class __SurveyDialogState extends State<_SurveyDialog> { _questionController = TextEditingController( text: widget.initialSurvey == null ? "" : widget.initialSurvey.question, ); - if (widget.initialSurvey != null) _choices = widget.initialSurvey.answers; + if (widget.initialSurvey != null) { + _choices = widget.initialSurvey.answers; + _allowNewChoices = widget.initialSurvey.allowNewChoicesCreation; + } } @override @@ -105,6 +111,15 @@ class __SurveyDialogState extends State<_SurveyDialog> { : null, )), ), + + // Allow users to create new choices + ListTile( + leading: Switch.adaptive( + value: _allowNewChoices, + onChanged: (v) => setState(() => _allowNewChoices = v), + ), + title: Text(tr("Allow users to create new choices")), + ) ]), ), );