mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 00:05:16 +00:00
Can block the creation of new responses on a survey
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import 'package:comunic/helpers/survey_helper.dart';
|
||||
import 'package:comunic/models/survey.dart';
|
||||
import 'package:comunic/models/survey_choice.dart';
|
||||
import 'package:comunic/ui/widgets/safe_state.dart';
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
import 'package:comunic/utils/ui_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@ -21,7 +22,7 @@ class SurveyWidget extends StatefulWidget {
|
||||
_SurveyWidgetState createState() => _SurveyWidgetState();
|
||||
}
|
||||
|
||||
class _SurveyWidgetState extends State<SurveyWidget> {
|
||||
class _SurveyWidgetState extends SafeState<SurveyWidget> {
|
||||
final SurveyHelper _helper = SurveyHelper();
|
||||
|
||||
Survey get survey => widget.survey;
|
||||
@ -42,6 +43,12 @@ class _SurveyWidgetState extends State<SurveyWidget> {
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
_buildUserResponse(),
|
||||
|
||||
// Offer to block the creation of new responses, if possible
|
||||
survey.allowNewChoicesCreation
|
||||
? _buildBlockNewResponsesLink()
|
||||
: Container(),
|
||||
|
||||
survey.hasResponses ? _buildChart() : _buildNoResponseNotice(),
|
||||
],
|
||||
);
|
||||
@ -109,6 +116,11 @@ class _SurveyWidgetState extends State<SurveyWidget> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBlockNewResponsesLink() => InkWell(
|
||||
onTap: _blockNewChoices,
|
||||
child: Text(tr("Block the creation of new responses")),
|
||||
);
|
||||
|
||||
Widget _buildChart() {
|
||||
return PieChart(
|
||||
dataMap: _buildDataMap(),
|
||||
@ -133,4 +145,21 @@ class _SurveyWidgetState extends State<SurveyWidget> {
|
||||
survey.setUserResponse(choice);
|
||||
});
|
||||
}
|
||||
|
||||
/// Block the creation of new choices on this survey
|
||||
void _blockNewChoices() async {
|
||||
try {
|
||||
if (!await showConfirmDialog(
|
||||
context: context,
|
||||
message: tr("Do you really want to block new responses ?"))) return;
|
||||
|
||||
await SurveyHelper.blockNewChoicesCreation(survey.postID);
|
||||
|
||||
setState(() => survey.allowNewChoicesCreation = false);
|
||||
} catch (e, s) {
|
||||
print("Could not block the creation of new choices! $e\n$s");
|
||||
showSimpleSnack(
|
||||
context, tr("Could not block the creation of new choices!"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user