想着自己可以搭建项目,将来升职加薪有希望,所以现在遇到的坑都记录下来,以便后续复盘!!
1、使用Dio,进行请求时,ios端出现报错 :
Unhandled Exception: Bad state: Insecure HTTP is not allowed by platform:
请在Xcode里面进行配置,方法如下:

在项目列表的,Runner->info.plist->information Property List里面新建App Transport Security Settings,然后在里面再新建Allow Arbitrary Loads,选择Yes就好了!!
2、flutter版本升级之后,遇到环境配置未更改导致出现的报错:
解决方案:
打开配置文件
open -e ~/.bash_profile
修改sdk路径完成之后在android studio 下方的的Terminal执行下面的适应
source ~/.bash_profile
OK,完事
3、textFile控件在ios出现输入文字或字母后,整体变成黑色方块的时候,解决方案: autocorrect: Platform.isIOS?false:true,
取消ios的自动联想就可以解决了
4、在使用floor搭建数据库的时候,有个问题就是创建database.g.dart这个文件,根据教程https://juejin.cn/post/6904269772158926855中的
'''
flutter packages pub run build_runner build
'''
进行文件的创建,但是后来发现报下面这个错误

解决方案如下:执行flutter clean->flutter pub get->flutter run->flutter packages pub run build_runner build然后就可以正确的出现文件了,出现的文件位置在

看到了吧,然后复制里面的内容就好了,还有个小细节,注意在database.dart的文件上面写进part of 'database.dart';
这个哦,要不然编译的时候就会报错哦
5、解决app启动1-3秒左右的白屏问题
造成原因:在flutter框架的代码加载内存这段时间内,是没有任何代码可以渲染的,所以才会导致出现1-3秒左右的白屏问题
解决方案:
使用flutter_native_splash这个插件,非常方便!!
使用也很简单:
1、导入包https://pub.dev/packages/flutter_native_splash
2、传入设置的图片资源或者设置其他的规则

这里需要注意下image这个资源,需要在这里进行声明,否则找不到的

而且文件的格式只能使用png的,使用其他的格式也会报错的
然后使用

6、在需要打包安卓的时候,发现在build栏里面没有Generate Signed Bundle or APK的选项,原来是因为android studio的版本和gradle的版本对应不上导致的,建议不要升级到最新版本的,毕竟很多插件都没有跟上更新的:
解决方案如下:

更改 ext.kotlin_version = '1.6.10'
更改 classpath 'com.android.tools.build:gradle:4.2.2'

更改distributionUrl=https://services.gradle.org/distributions/gradle-6.7.1-bin.zip
这样就可以出现创建签名的选项了
7.zsh: command not found: flutter
出现无法找到flutter的提示,解决方案有两种如下:
第一种,需要每次进入项目的时候都要用的(不建议):
在该项目的命令行里面输入 source ~/.bash_profile,就可以解决了
第二种,永久性解决:

完美解决!!!!
8.在集成百度语音sdk的时候,ios端报错,报错
library not found for -libBaiduSpeechSDK

解决方案如下:
打开Runner-Build Settings,然后搜索Search Path,打开Library Search paths,里面有三个环境下的设置,然后点开右边的更改设置,如下:

更改成recursive,然后就可以解决了
9.在android集成百度语音sdk的时候,导入部分文件出现了,一直导入无效的情况,如下:

这是因为在build.gradle中的依赖,没有添加以下的引用
implementation fileTree(dir: 'libs', include: ['*.jar'])

添加之后sync now就可以了
10.在android项目中引用flutter的module出现不可引用的问题,如下

原因是构建储存库的出现问题,在setting.gradle设置目录中,如下:


解决方案如下:
把RepositoriesMode.FAIL_ON_PROJECT_REPOS更改为RepositoriesMode.PREFER_SETTINGS就可以解决了!!!
后面持续更新!!
网友评论