Flutter应用仅iOS14设备出现资源加载失败错误求助
iOS 14设备上Flutter应用加载资源失败问题
Fatal Exception: FlutterError
Unable to load asset: assets/images/settings_unselected_icon.png.. Error thrown Instance of 'ErrorDescription'.

应用仅在iPhone iOS 14设备上出现该错误,其他iOS版本运行正常。
相关代码
class FitnessAppHomeScreen extends Stateful Widget { const FitnessAppHomeScreen({Key? key}) : super(key: key); @override _FitnessAppHomeScreenState createState() => _FitnessAppHomeScreenState(); } class _FitnessAppHomeScreenState extends State<FitnessAppHomeScreen> { List<TabIconData> tabIconsList = TabIconData.tabIconsList; var _selectedTab = _SelectedTab.home; void _handleIndexChanged(int i) { setState(() { _selectedTab = _SelectedTab.values[i]; }); } Widget tabBody = Container( color: Colors.white, ); @override void initState() { PrivacyScreen.instance.enable( iosOptions: const PrivacyIosOptions( enablePrivacy: true, privacyImageName: "LaunchImage", autoLockAfterSeconds: 1, lockTrigger: IosLockTrigger.didEnterBackground, ), androidOptions: const PrivacyAndroidOptions( enableSecure: true, autoLockAfterSeconds: 1, ), backgroundColor: Colors.grey.withOpacity(0.11), blurEffect: PrivacyBlurEffect.dark, ); for (final tab in tabIconsList) { tab.isSelected = false; } tabIconsList[0].isSelected = true; tabBody = const CustomizedView(); dataStore.setSessions('currentSession', 0); incrementUserSession(); if (Platform.isIOS) { requestAttributionDetails(); } Future.delayed(const Duration(milliseconds: 200), () { if (dataStore.getSettings('pin').isEmpty) { PrivacyScreen.instance.pauseLock(); } else { PrivacyScreen.instance.resumeLock(); PrivacyScreen.instance.unlock(); PrivacyScreen.instance.lock(); } }); super.initState(); } Future<void> requestAttributionDetails() async { String? token; try { token = await FlutterAsaAttribution.instance.attributionToken(); if (kDebugMode) { print(token); } } catch (e) { if (kDebugMode) { print(e); } } } @override Widget build(BuildContext context) { return Container( color: Colors.white, child: Scaffold( backgroundColor: Colors.transparent, body: GestureDetector( onTap: () { final currentFocus = FocusScope.of(context); if (!currentFocus.hasPrimaryFocus) { currentFocus.unfocus(); } }, child: Stack( children: <Widget>[ tabBody, Column( children: [ const Expanded( child: SizedBox(), ), DotNavigationBar( paddingR: const EdgeInsets.only(bottom: 5, top: 5), marginR: const EdgeInsets.symmetric( horizontal: 35, vertical: 15), currentIndex: _SelectedTab.values.indexOf(_selectedTab), dotIndicatorColor: Colors.white, selectedItemColor: const Color(0xFF2EBDD8), unselectedItemColor: Colors.grey[300], enableFloatingNavBar: true, enablePaddingAnimation: false, boxShadow: const [ BoxShadow( offset: Offset(1, 1), color: Colors.black12, blurRadius: 5.0, spreadRadius: 1.0) ], onTap: (index) { _handleIndexChanged(index); if (index == 0) { if (!mounted) { return; } setState(() { tabBody = const CustomizedView(); }); } else if (index == 1) { if (!mounted) { return; } setState(() { tabBody = const GenerateCodeScreen(); }); } else if (index == 2) { if (!mounted) { return; } setState(() { tabBody = const HistoryPage(); }); } else if (index == 3) { if (!mounted) { return; } setState(() { tabBody = const SettingsPage(); }); } }, items: [ DotNavigationBarItem( icon: Image.asset( 'assets/images/scanner_unselected_icon.png', scale: 1.9, color: _selectedTab.index == 0 ? const Color(0xFF2EBDD8) : null), selectedColor: const Color(0xFF2EBDD8), ), DotNavigationBarItem( icon: Image.asset( 'assets/images/generate_unselected_icon.png', scale: 1.9, color: _selectedTab.index == 1 ? const Color(0xFF2EBDD8) : null), selectedColor: const Color(0xFF2EBDD8), ), DotNavigationBarItem( icon: Image.asset( 'assets/images/history_unselected.png', scale: 1.9, color: _selectedTab.index == 2 ? const Color(0xFF2EBDD8) : null), selectedColor: const Color(0xFF2EBDD8), ), DotNavigationBarItem( icon: Image.asset( 'assets/images/settings_unselected_icon.png', scale: 1.9, color: _selectedTab.index == 3 ? const Color(0xFF2EBDD8) : null), selectedColor: const Color(0xFF2EBDD8), ), ], ) ], ), ], ), ), ), ); } }
pubspec.yaml配置
flutter: # The following line ensures that the Material Icons font is # included with your application, so that you can use the images in # the material Icons class. uses-material-design: true assets: - assets/images/calender_icon.png - assets/images/call.png - assets/images/barcode.png - assets/images/clipboard_icon.png - assets/images/clipboard_icon.png - assets/images/contacts_icon.png - assets/images/email.png - assets/images/email_icon.png - assets/images/fb.png - assets/images/fb-white.png - assets/images/gallery_icon.png - assets/images/photo.png - assets/images/generate_selected_icon.png - assets/images/generate_unselected_icon.png - assets/images/history_selected.png - assets/images/history_unselected.png - assets/images/rateus.png - assets/images/rateus_circle.png - assets/images/rateus_star.png - assets/images/ig.png - assets/images/ig-white.png - assets/images/sc.png - assets/images/sc1.png - assets/images/sc1-white.png - assets/images/messages_icon.png - assets/images/phone_icon.png - assets/images/scanner_selected_icon.png - assets/images/scanner_unselected_icon.png - assets/images/speech-bubble.png - assets/images/spotify_icon.png - assets/images/spotify_icon-white.png - assets/images/settings_selected_icon.png - assets/images/settings_unselected_icon.png - assets/images/telegram.png - assets/images/text_icon.png - assets/images/tg.png - assets/images/tg-white.png - assets/images/tool_img.png - assets/images/transparent.png - assets/images/twitter_icon.png - assets/images/twitter_icon-white.png - assets/images/url_icon.png - assets/images/viber.png - assets/images/viber-white.png - assets/images/video_on.png - assets/images/video_off.png - assets/images/whatsapp.png - assets/images/whatsapp-white.png - assets/images/wifi_icon.png - assets/images/girl.png - assets/images/group_dots.png - assets/images/intro_1.png - assets/images/intro_2.png - assets/images/red_dot.png - assets/images/white_dot.png - assets/images/next_icon.png - assets/images/scan_icon.png - assets/images/idfa_allow.png - assets/images/heart.png - assets/images/analytics.png - assets/images/success.png - assets/sound/scan_beep.mp3 - assets/svg/google.svg - assets/svg/ebay.svg - assets/svg/amazon.svg - assets/svg/transparent.svg - assets/svg/google_shopping.svg - assets/svg/google-shopping-logo.png - assets/svg/openfoodfacts.svg fonts: - family: SFPRO fonts: - asset: assets/fonts/sfpro/SFProDisplay-Bold.ttf weight: 700 - asset: assets/fonts/sfpro/SFProDisplay-Medium.ttf weight: 400 - asset: assets/fonts/sfpro/SFProDisplay-Semibold.ttf weight: 500
已尝试的解决方案
已尝试以下清理操作,但均未解决问题:
- 快速清理缓存
- 通过Android Studio工具菜单执行Flutter -> Clean
- 执行File -> Invalidate Caches / Restart
- 终端运行
flutter clean - 删除pubspec.lock文件
恳请各位帮忙解决该问题。
内容的提问来源于stack exchange,提问作者Ramy Aly
相关产品推荐
相关产品推荐

