AOSSIE-Org / AOSSIE-Org/Resonate

Division by zero

Open
#799 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Dart
Stars
344
Forks
350
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.