AOSSIE-Org / AOSSIE-Org/Resonate

Division by zero

Abierto
#799 1 comentario 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Dart
Estrellas
344
Forks
350
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

### 🐛 Describe the bug

The application crashes when calculating the average rating due to a division by zero error. This occurs when ratingCount is 0, which leads to an invalid division operation.

Steps to Reproduce
Ensure ratingCount is 0
Trigger any code path that calculates the average rating
The app crashes immediately

double ratingTotal = 0;
int ratingCount = 0;

double averageRating = ratingTotal / ratingCount; // ❌ Crash here
print(averageRating);

Unsupported operation: Infinity or NaN toInt

#0 double.toInt (dart:core-patch/double.dart:xxx)
#1 YourWidget.build (package:your_app/your_widget.dart:xx)
#2 StatelessElement.build (package:flutter/src/widgets/framework.dart:xxx)
#3 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:xxx)
Expected Behavior

The app should handle cases where ratingCount == 0 gracefully, without crashing.

💡 Suggested Fix

Add a guard condition before division:

double averageRating = ratingCount == 0
? 0
: ratingTotal / ratingCount;

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.