일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- guideline 4.3(a)
- 에러
- flutter_dotenv
- infinity or nan toint
- information needed
- tflite_flutter
- app store connect guideline
- app stroe connect guideline
- exception caught by image resource service
- 플러터
- undefined name
- permissiondeniedexception
- guideline 1.5
- buildcontext
- 채팅 메시지 정렬
- app completeness
- flutter_secure_storage
- exception
- pub.dev
- .dio
- GetX
- providernotfoundexception
- flutter doctor -v
- appstore connect guideline
- youtube_player_flutter
- dart sdk version upgrade
- AI
- appstroe connect guideline
- withopacity
- Flutter
Archives
- Today
- Total
min_chan님의 블로그
[Flutter] - Unknown operation: Infinity or Nan toInt 본문
에러 발생(1)
- 플러터에서 파이어베이스 db를 사용.
- 밸런스 게임의 전체 참여자 수와 A를 선택한 참여자, B를 선택한 참여자를 비교하여 결과를 보여주려는 연산 코드를 작성하고 있는 도중 에러 발생.
에러 코드 & 사진 (2)
final countA = snapshot.data!.docs[index]['countA'];
final countB = snapshot.data!.docs[index]['countB'];
final sumCount = snapshot.data!.docs[index]['sumCount'];
double percentA = (countA / sumCount);
double percentB = (countB / sumCount);
int roundA = (percentA * 100).round();
int roundB = (percentB * 100).round();
에러 발생 원인 (3)
- 파이어베이스 초기 세팅인 sumCount가 0으로 설정되어 있어 해당 필드를 바로 불러왔을 경우 percentA 와 percentB를 구하는 연산 과정에서 무한대로 빠져버린다.
해결 방안 & 코드 (4)
- sumCount가 0인 경우 삼항 연산자를 사용하여 예외처리를 해줬다.
final countA = snapshot.data!.docs[index]['countA'];
final countB = snapshot.data!.docs[index]['countB'];
final sumCount = snapshot.data!.docs[index]['sumCount'];
double percentA = sumCount != 0 ? (countA / sumCount) : 0.0;
double percentB = sumCount != 0 ? (countB / sumCount) : 0.0;
int roundA = (percentA * 100).round();
int roundB = (percentB * 100).round();
결과 스크린 샷 (5)
1. 모두 0일 경우 2. 0이 아닐 경우
'Flutter' 카테고리의 다른 글
[Flutter AI] - 모델 생성 (0) | 2025.01.10 |
---|---|
[Flutter AI] - 머신러닝과 딥러닝 (0) | 2025.01.10 |
[Flutter] - url에서 Youtube Video Id 추출하는 법 (0) | 2025.01.09 |
[Flutter] - Daum api 동영상 재생 에러 (0) | 2025.01.09 |
[Flutter] - 채팅 메시지 정렬 (0) | 2025.01.09 |