AOSSIE-Org / AOSSIE-Org/Resonate

Division by zero

Aperta
#799 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Dart
Stelle
344
Fork
350
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

### 🐛 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;

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.