mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-03 19:54:12 +00:00 
			
		
		
		
	Can create a new choice for the survey
This commit is contained in:
		@@ -44,6 +44,9 @@ class _SurveyWidgetState extends SafeState<SurveyWidget> {
 | 
			
		||||
        ),
 | 
			
		||||
        _buildUserResponse(),
 | 
			
		||||
 | 
			
		||||
        // Offer the user to create a new choice on the survey, if possible
 | 
			
		||||
        survey.allowNewChoicesCreation ? _buildNewChoiceLink() : Container(),
 | 
			
		||||
 | 
			
		||||
        // Offer to block the creation of new responses, if possible
 | 
			
		||||
        survey.canBlockNewChoicesCreation
 | 
			
		||||
            ? _buildBlockNewResponsesLink()
 | 
			
		||||
@@ -116,9 +119,20 @@ class _SurveyWidgetState extends SafeState<SurveyWidget> {
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Widget _buildBlockNewResponsesLink() => InkWell(
 | 
			
		||||
        onTap: _blockNewChoices,
 | 
			
		||||
        child: Text(tr("Block the creation of new responses")),
 | 
			
		||||
  Widget _buildNewChoiceLink() => Padding(
 | 
			
		||||
        padding: const EdgeInsets.all(8.0),
 | 
			
		||||
        child: InkWell(
 | 
			
		||||
          onTap: _createNewChoices,
 | 
			
		||||
          child: Text(tr("Create a new choice")),
 | 
			
		||||
        ),
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
  Widget _buildBlockNewResponsesLink() => Padding(
 | 
			
		||||
        padding: const EdgeInsets.all(8.0),
 | 
			
		||||
        child: InkWell(
 | 
			
		||||
          onTap: _blockNewChoices,
 | 
			
		||||
          child: Text(tr("Block the creation of new responses")),
 | 
			
		||||
        ),
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
  Widget _buildChart() {
 | 
			
		||||
@@ -146,6 +160,30 @@ class _SurveyWidgetState extends SafeState<SurveyWidget> {
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// Create a new choice
 | 
			
		||||
  void _createNewChoices() async {
 | 
			
		||||
    try {
 | 
			
		||||
      final newChoice = await askUserString(
 | 
			
		||||
        context: context,
 | 
			
		||||
        title: tr("New choice"),
 | 
			
		||||
        message: tr("Please specify the new choice for the survey"),
 | 
			
		||||
        defaultValue: "",
 | 
			
		||||
        hint: tr("New choice..."),
 | 
			
		||||
        maxLength: 50,
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
      if (newChoice == null || newChoice.isEmpty) return;
 | 
			
		||||
 | 
			
		||||
      await SurveyHelper.createNewChoice(survey.postID, newChoice);
 | 
			
		||||
 | 
			
		||||
      // TODO : reload survey
 | 
			
		||||
    } catch (e, s) {
 | 
			
		||||
      print("Could not create new survey choice! $e\n$s");
 | 
			
		||||
      showSimpleSnack(
 | 
			
		||||
          context, tr("Could not create a new choice for this survey!"));
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// Block the creation of new choices on this survey
 | 
			
		||||
  void _blockNewChoices() async {
 | 
			
		||||
    try {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user