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:
|
case PostKind.SURVEY:
|
||||||
request.addString("question", post.survey.question);
|
request.addString("question", post.survey.question);
|
||||||
request.addString("answers", post.survey.answers.join("<>"));
|
request.addString("answers", post.survey.answers.join("<>"));
|
||||||
|
request.addBool("allowNewAnswers", post.survey.allowNewChoicesCreation);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PostKind.YOUTUBE:
|
case PostKind.YOUTUBE:
|
||||||
|
@ -12,12 +12,15 @@ import 'package:meta/meta.dart';
|
|||||||
class NewSurvey {
|
class NewSurvey {
|
||||||
final String question;
|
final String question;
|
||||||
final Set<String> answers;
|
final Set<String> answers;
|
||||||
|
final bool allowNewChoicesCreation;
|
||||||
|
|
||||||
const NewSurvey({
|
const NewSurvey({
|
||||||
@required this.question,
|
@required this.question,
|
||||||
@required this.answers,
|
@required this.answers,
|
||||||
|
@required this.allowNewChoicesCreation,
|
||||||
}) : assert(question != null),
|
}) : assert(question != null),
|
||||||
assert(answers.length > 1);
|
assert(answers.length > 1),
|
||||||
|
assert(allowNewChoicesCreation != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
class NewPost {
|
class NewPost {
|
||||||
|
@ -29,12 +29,15 @@ class __SurveyDialogState extends State<_SurveyDialog> {
|
|||||||
TextEditingController _questionController;
|
TextEditingController _questionController;
|
||||||
final _choiceController = TextEditingController();
|
final _choiceController = TextEditingController();
|
||||||
var _choices = Set<String>();
|
var _choices = Set<String>();
|
||||||
|
var _allowNewChoices = false;
|
||||||
|
|
||||||
bool get canConfirm =>
|
bool get canConfirm =>
|
||||||
_questionController.text.length > 2 && _choices.length > 1;
|
_questionController.text.length > 2 && _choices.length > 1;
|
||||||
|
|
||||||
NewSurvey get newSurvey =>
|
NewSurvey get newSurvey => NewSurvey(
|
||||||
NewSurvey(question: _questionController.text, answers: _choices);
|
question: _questionController.text,
|
||||||
|
answers: _choices,
|
||||||
|
allowNewChoicesCreation: _allowNewChoices);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -42,7 +45,10 @@ class __SurveyDialogState extends State<_SurveyDialog> {
|
|||||||
_questionController = TextEditingController(
|
_questionController = TextEditingController(
|
||||||
text: widget.initialSurvey == null ? "" : widget.initialSurvey.question,
|
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
|
@override
|
||||||
@ -105,6 +111,15 @@ class __SurveyDialogState extends State<_SurveyDialog> {
|
|||||||
: null,
|
: 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