mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-25 22:39:22 +00:00
Allow to create new choices on survey on its creation
This commit is contained in:
parent
ef0ae2a586
commit
b4465cc70c
@ -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:
|
||||
|
@ -12,12 +12,15 @@ import 'package:meta/meta.dart';
|
||||
class NewSurvey {
|
||||
final String question;
|
||||
final Set<String> 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 {
|
||||
|
@ -29,12 +29,15 @@ class __SurveyDialogState extends State<_SurveyDialog> {
|
||||
TextEditingController _questionController;
|
||||
final _choiceController = TextEditingController();
|
||||
var _choices = Set<String>();
|
||||
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")),
|
||||
)
|
||||
]),
|
||||
),
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user