mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 12:14:11 +00:00 
			
		
		
		
	Do not render survey pie chart which have not response
This commit is contained in:
		@@ -33,6 +33,9 @@ class Survey {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  bool get hasResponded => this.userChoice != null && this.userChoice > 0;
 | 
					  bool get hasResponded => this.userChoice != null && this.userChoice > 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  bool get hasResponses =>
 | 
				
			||||||
 | 
					      this.choices.where((f) => f.responses > 0).length > 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  SurveyChoice get userResponse {
 | 
					  SurveyChoice get userResponse {
 | 
				
			||||||
    if (!hasResponded) return null;
 | 
					    if (!hasResponded) return null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -42,9 +42,7 @@ class _SurveyWidgetState extends State<SurveyWidget> {
 | 
				
			|||||||
          style: TextStyle(fontWeight: FontWeight.bold),
 | 
					          style: TextStyle(fontWeight: FontWeight.bold),
 | 
				
			||||||
        ),
 | 
					        ),
 | 
				
			||||||
        _buildUserResponse(),
 | 
					        _buildUserResponse(),
 | 
				
			||||||
        PieChart(
 | 
					        survey.hasResponses ? _buildChart() : _buildNoResponseNotice(),
 | 
				
			||||||
          dataMap: _buildDataMap(),
 | 
					 | 
				
			||||||
        ),
 | 
					 | 
				
			||||||
      ],
 | 
					      ],
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -98,15 +96,28 @@ class _SurveyWidgetState extends State<SurveyWidget> {
 | 
				
			|||||||
      items: survey.choices
 | 
					      items: survey.choices
 | 
				
			||||||
          .map(
 | 
					          .map(
 | 
				
			||||||
            (f) => DropdownMenuItem<SurveyChoice>(
 | 
					            (f) => DropdownMenuItem<SurveyChoice>(
 | 
				
			||||||
                  value: f,
 | 
					              value: f,
 | 
				
			||||||
                  child: Text(f.name),
 | 
					              child: Text(f.name),
 | 
				
			||||||
                ),
 | 
					            ),
 | 
				
			||||||
          )
 | 
					          )
 | 
				
			||||||
          .toList(),
 | 
					          .toList(),
 | 
				
			||||||
      onChanged: _respondToSurvey,
 | 
					      onChanged: _respondToSurvey,
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Widget _buildChart() {
 | 
				
			||||||
 | 
					    return PieChart(
 | 
				
			||||||
 | 
					      dataMap: _buildDataMap(),
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Widget _buildNoResponseNotice() {
 | 
				
			||||||
 | 
					    return Padding(
 | 
				
			||||||
 | 
					      padding: const EdgeInsets.all(16.0),
 | 
				
			||||||
 | 
					      child: Text(tr("No response yet to this survey.")),
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /// Respond to survey
 | 
					  /// Respond to survey
 | 
				
			||||||
  Future<void> _respondToSurvey(SurveyChoice choice) async {
 | 
					  Future<void> _respondToSurvey(SurveyChoice choice) async {
 | 
				
			||||||
    // Send the response to the server
 | 
					    // Send the response to the server
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user