Flutter intl_phone_number_input的getRegionInfoFromPhoneNumber函数报错求助
Flutter intl_phone_number_input 0.7.1 getRegionInfoFromPhoneNumber 报错求助
我在使用Flutter的intl_phone_number_input包(0.7.1最新版本)中的getRegionInfoFromPhoneNumber函数时遇到问题:该函数此前可正常运行,但今日测试时出现以下错误。
错误详情
TypeError: Cannot read properties of undefined (reading 'PhoneNumberUtil') at getRegionInfo (http://localhost:51866/packages/libphonenumber_web/src/libphonenumber_plugin.dart.lib.js:56:58) at getRegionInfo.next (<anonymous>) at runBody (http://localhost:51866/dart_sdk.js:40660:34) at Object._async [as async] (http://localhost:51866/dart_sdk.js:40691:7) at libphonenumber_plugin.LibPhoneNumberPlugin.new.getRegionInfo (http://localhost:51866/packages/libphonenumber_web/src/libphonenumber_plugin.dart.lib.js:55:20) at getRegionInfo (http://localhost:51866/packages/libphonenumber_plugin/src/phone_number_util.dart.lib.js:49:75) at getRegionInfo.next (<anonymous>) at runBody (http://localhost:51866/dart_sdk.js:40660:34) at Object._async [as async] (http://localhost:51866/dart_sdk.js:40691:7) at PhoneNumberUtil.getRegionInfo (http://localhost:51866/packages/libphonenumber_plugin/src/phone_number_util.dart.lib.js:48:20) at getRegionInfo (http://localhost:51866/packages/intl_phone_number_input/src/utils/phone_number/phone_number_util.dart.lib.js:158:65) at getRegionInfo.next (<anonymous>) at runBody (http://localhost:51866/dart_sdk.js:40660:34) at Object._async [as async] (http://localhost:51866/dart_sdk.js:40691:7) at PhoneNumberUtil.getRegionInfo (http://localhost:51866/packages/intl_phone_number_input/src/utils/phone_number/phone_number_util.dart.lib.js:157:20) at getRegionInfoFromPhoneNumber (http://localhost:51866/packages/intl_phone_number_input/src/utils/phone_number/phone_number_util.dart.lib.js:476:68) at getRegionInfoFromPhoneNumber.next (<anonymous>) at runBody (http://localhost:51866/dart_sdk.js:40660:34) at Object._async [as async] (http://localhost:51866/dart_sdk.js:40691:7) at PhoneNumber.getRegionInfoFromPhoneNumber (http://localhost:51866/packages/intl_phone_number_input/src/utils/phone_number/phone_number_util.dart.lib.js:474:20) at upload_data_form._UploadDataFormState.new.<anonymous> (http://localhost:51866/packages/excelit/widgets/remember_me.dart.lib.js:13587:84) at Generator.next (<anonymous>) at runBody (http://localhost:51866/dart_sdk.js:40660:34) at Object._async [as async] (http://localhost:51866/dart_sdk.js:40691:7) at http://localhost:51866/packages/excelit/widgets/remember_me.dart.lib.js:13531:218 at _RootZone.runUnary (http://localhost:51866/dart_sdk.js:40511:59) at _FutureListener.then.handleValue (http://localhost:51866/dart_sdk.js:35438:29) at handleValueCallback (http://localhost:51866/dart_sdk.js:35999:49) at _Future._propagateToListeners (http://localhost:51866/dart_sdk.js:36037:17) at [_completeWithValue] (http://localhost:51866/dart_sdk.js:35872:23) at async._AsyncCallbackEntry.new.callback (http://localhost:51866/dart_sdk.js:35906:35) at Object._microtaskLoop (http://localhost:51866/dart_sdk.js:40778:13) at _startMicrotaskLoop (http://localhost:51866/dart_sdk.js:40784:13) at http://localhost:51866/dart_sdk.js:36261:9
代码场景说明
我的代码会逐行读取Excel文件并创建Client对象,处理后的手机号格式为+96181816583这类合法格式,代码示例如下:
//TEMPLIST: [Client A, Mr. Ahmad, ahmad@mindit.com, Lebanon, Beirut, Badaro, 96181816583, -, -] //处理后的手机号为 +96181816583,格式合法 PhoneNumber number1 = await PhoneNumber .getRegionInfoFromPhoneNumber( (tempList.elementAt(6).substring(0, 1) != '+') ? '+${tempList.elementAt(6).replaceAll(' ', '')}' : tempList.elementAt(6).replaceAll(' ', ''),) .onError((error, stackTrace) { failureSnackBar(context, 'Invalid or missing phone_num in ${file.name} row ${row.elementAt(0)!.rowIndex + 1}'); Navigator.pop(context); breakLoop = true; return PhoneNumber(); });
问题补充
此前相同的Excel文件可正常解析手机号,但现在无法运行,即使手动指定isoCode仍会出现相同错误,恳请提供解决帮助!
内容的提问来源于stack exchange,提问作者lou_codes
相关产品推荐
相关产品推荐

