那些年儿,遇到的flutter问题

#0

code能跑动,但跑完后就自动报如上得错误。

解决方法:

  • why

    新得模拟器:版本号——Q存在问题

    solve:通过Device Manager创建版本号为Pie的模拟器,可正常运行

参考资料:

Fix Flutter Debug Error on Android Emulator “Error connecting to the service protocol:HttpException”

#01
arget of URI doesn’t exist: package:shared_preferences/shared_preferences.dart

解決方法:

flutter packages get 

更新依赖包

当你在添加一个包后首次运行(IntelliJ中的’Packages Get’)flutter packages get,Flutter将找到包的版本保存在pubspec.lock。这确保了如果您或您的团队中的其他开发人员运行flutter packages get后回获取相同版本的包。

如果要升级到软件包的新版本,例如使用该软件包中的新功能,请运行flutter packages upgrade(在IntelliJ中点击Upgrade dependencies)。 这将根据您在pubspec.yaml中指定的版本约束下载所允许的最高可用版本。

flutter clean //删除构建/目录。

#02

一直停留在如下的下载包状态:

Running "flutter packages get" in project_name...

解决方法:

windows下添加环境变量,改变下载地址为国内镜像:

PUB_HOSTED_URL  https://pub.flutter-io.cn
FLUTTER_STORAGE_BASE_URL  https://storage.flutter-io.cn

执行flutter doctor命令,检测。

在项目命令行中,flutter packages get

参考资料:Flutter 卡在 package get 的解决办法

### 如何在 Flutter 项目中正确配置和使用 Podfile #### 解析 Podfile 的作用 当在项目目录中执行 `pod install` 命令时,CocoaPods 会解析 Podfile 文件。该工具读取文件中的依赖信息,确定需要安装哪些库及其版本[^1]。 #### 默认的 Podfile 结构 通常情况下,在创建一个新的 Flutter 项目时,默认会在 iOS 子项目的根目录下生成一个名为 Podfile 的文件。默认结构如下: ```ruby # Uncomment this line to define a global platform for your project platform :ios, '9.0' target 'Runner' do use_frameworks! use_modular_headers! flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) end post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings['ENABLE_BITCODE'] = 'NO' end end end ``` 这段脚本指定了平台最低支持版本,并设置了目标 Runner 使用框架模式以及模块化头文件。最后还有一段 post-install 脚本来禁用 bitcode 编译选项。 #### 添加第三方 CocoaPod 库 如果想要向 Flutter 项目添加额外的原生库,则可以在上述代码片段中的 `do...end` 中间部分加入所需的 pod 来源声明语句。例如要引入 Firebase SDK 可能看起来像这样: ```ruby target 'Runner' do use_frameworks! use_modular_headers! # Add the Firebase pod for Google Analytics pod 'Firebase/Analytics' # Add the pods for any other Firebase products you want to use in your app # For example, to use Firebase Authentication and Cloud Firestore pod 'Firebase/Auth' pod 'Firebase/Firestore' flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) end ``` 完成这些更改之后再次运行 `pod install` 即可更新 Pods 并使新的依赖生效。 #### 处理不同 Swift 版本兼容性问题 有时可能会遇到由于 Swift 不同版本之间不完全兼容而导致编译错误的情况。此时可以考虑采用条件导入的方式解决这个问题,比如改成下面的形式来处理可能存在的路径差异[^4]: ```objectivec #if __has_include(<install_plugin/install_plugin-Swift.h>) #import <install_plugin/install_plugin-Swift.h> #else #import "install_plugin-Swift.h" #endif ``` 这种写法能够确保即使是在不同的开发环境中也能正常工作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值