AOSSIE-Org / AOSSIE-Org/Resonate

Division by zero

オープン
#799 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Dart
スター
344
フォーク
350
PR マージ指標
30日以内にマージされた PR はありません

説明

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

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。