adhan 2.0.0空安全版高纬度计算礼拜时间抛NaN异常
问题说明
使用Flutter/Dart生态的adhan礼拜时间计算包(版本:^2.0.0-nullsafety.2)时,若传入坐标的纬度值处于(-90, -67.5944046]或[65.9277379, 90)的高纬度区间,程序会触发未处理异常。
最小复现代码
import 'package:adhan/adhan.dart'; void main() { //latitude values between (-67.5944046 and -90) and between (65.9277379 and 90) //throw Unhandled exception! // var prayerTimes = PrayerTimes(Coordinates(-67.5944046, 120), // DateComponents.from(DateTime.now()), CalculationMethod.umm_al_qura.getParameters()); var prayerTimes = PrayerTimes(Coordinates(65.9277379, 120), DateComponents.from(DateTime.now()), CalculationMethod.umm_al_qura.getParameters()); print(prayerTimes.fajr); }
预期行为
传入合法经纬度参数时,应正常输出对应坐标、对应日期的准确礼拜时间。
实际行为
程序抛出未处理异常后退出,错误提示为Invalid argument(s): value should not be infinite or NaN,异常栈定位到TimeComponents.fromDouble方法,完整异常信息如下:
C:/Flutter_SDK/flutter/bin/cache/dart-sdk/bin/dart.exe --enable-asserts "E:\Flutter_UI\hij_greg_temp - Copy\lib\main.dart" Unhandled exception: Invalid argument(s): value should not be infinite or NaN #0 TimeComponents.fromDouble (package:adhan/src/data/time_components.dart:12:7) #1 new PrayerTimes._ (package:adhan/src/prayer_times.dart:133:37) #2 new PrayerTimes (package:adhan/src/prayer_times.dart:53:24) #3 main (package:hij_greg_temp/main.dart:10:21) #4 _delayEntrypointInvocation. (dart:isolate-patch/isolate_patch.dart:297:19) #5 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12) Process finished with exit code 255
环境信息
当前Flutter环境(flutter doctor执行结果):
Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel beta, 3.1.0-9.0.pre, on Microsoft Windows [Version 10.0.19043.1766], locale en-US) [√] Android toolchain - develop for Android devices (Android SDK version 32.0.0) [√] Chrome - develop for the web [!] Visual Studio - develop for Windows (Visual Studio Enterprise 2019 16.11.1) X Visual Studio is missing necessary components. Please re-run the Visual Studio installer for the "Desktop development with C++" workload, and include these components: MSVC v142 - VS 2019 C++ x64/x86 build tools - If there are multiple build tool versions available, install the latest C++ CMake tools for Windows Windows 10 SDK [√] Android Studio (version 2021.1) [√] Android Studio (version 4.1) [√] Android Studio (version 4.2) [√] VS Code (version 1.68.1) [√] Connected device (4 available) [√] HTTP Host Availability ! Doctor found issues in 1 category.
补充说明
- 该包
^1.1.14旧版本无此问题,但旧版本未支持空安全,无法适配当前项目的空安全要求,无法回退使用。
内容的提问来源于stack exchange,提问作者MAlhamry
相关产品推荐
相关产品推荐

