189 8069 5689

flutter2.1,flutter210键盘问题

flutter项目升级2.0过程填坑记录

在此之前先推荐看大佬的: 填坑指导

成都创新互联专注于企业成都全网营销推广、网站重做改版、颍东网站定制设计、自适应品牌网站建设、H5响应式网站商城网站建设、集团公司官网建设、成都外贸网站制作、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为颍东等各大城市提供网站开发制作服务。

iOS需要注意:

1、flutter2.0要求cocoapods 升级到1.9.0

详情看这篇博客

2、原来flutter项目中的podfile文件是旧版本的ccocoapods了,删除podfile和对应的.lock,然后flutter项目重新运行使用它自动生成的podfile文件

3、安装CocoaPods

卸载cocoapods:sudo gem uninstall cocoapods

查看cocoapods版本:pod --version

指定版本安装:

sudo gem install -n /usr/local/bin cocoapods -v 1.9.3(新MacOS系统升级)

不指定版本安装

sudo gem install -n /usr/local/bin cocoapods

说明 :老项目sdk1.17.0===升级到2.0.1,当前所有操作基于win平台

到此为止环境已经准备妥当,正式进入项目修改。

所有的插件都要适配到空安全,插件是否支持均会有对应说明Null safety,适配过程不确定版本的话,可以使用dio: any,适配完事后再在pubspec.lock文件中查看具体的版本修改过来,实在有部分插件没有支持的,参考下面

部分插件在适配空安全的版本放弃维护了,得自行更新或寻找替代,如: flutter_swiper 变为 flutter_swiper_null_safety ,插件更新后要注意项目中的用法是否需要更新

2.1.1: 以前采用的是 provide 插件共享全局数据,现在变化为 provider ,用法改变, 点击参考 ,以防文章丢失,我重复一遍:

比如:

2.1.2: dio版本升级到4.0.0最新版后,部分用法改变

2.2.1

2.2.2

解决方案:

2.2.3

解决方案:

2.2.4

解决方案:

2.2.5

解决方案:

2.2.6

解决方案:

2.2.7

解决方案:

2.2.8

解决方案: child 换为sliver

2.2.8.1

解决方案: 项目目录下: android--app-build.gradle --minSdkVersion改为:18 或者19

2.2.8.2

解决方案: 在pubspec.yarm管理里面添加:publish_to

2.2.8.3

解决方案: video_player升级后字段发生了变化,initialized字段更换为:isInitialized(_controller.value.isInitialized)

2.2.8.4

解决方案:

2.2.8.5

解决方案:

2.2.8.6

解决方案: 方案一:删除ios目录下的Podfile.lock 文件然后重新运行 pod install命令

方案二:删除ios目录下的Podfile.lock与Podfile文件 重新运行flutter run或flutter build ios

方案三:删除ios目录,重新运行 flutter create . 命令,注意有"."这个符号不要忘记

2.2.8.7

这个报错一般对应的就是下面的报错,注意看后面的报错信息,看是哪个插件报错。

解决方案: 把Podfile的版本注释打开,改为platform :ios, '9.0' 或者是更高的版本

全局替换

1.将new List() 替换为[];

2.TextField的inputFormatters:[WhitelistingTextInputFormatter.digitsOnly] 替换为[FilteringTextInputFormatter.digitsOnly]

3.TextField的inputFormatters:[WhitelistingTextInputFormatter(RegExp("[a-z|A-Z|0-9]"))]替换为FilteringTextInputFormatter.allow(RegExp("[a-z|A-Z|0-9]"))

4.Stack组件中overflow: Overflow.visible改为 clipBehavior: Clip.none;overflow: Overflow.clip改为clipBehavior:Clip.hardEdge

5.ListWheelScrollView组件中clipToSize = false改为clipBehavior: Clip.none,clipToSize = true改为 Clip.hardEdge

6.TextField中maxLengthEnforced: true改为maxLengthEnforcement:MaxLengthEnforcement.enforced

7.FlatButton、RaisedButton、OutlineButton的变化: 官方参考

颜色的属性发生了变化,由原来的Color 变为了MaterialStatePropertyColor, 这是未了解决不同状态(pressed、hovered、focused、disabled)下按钮颜色的变化

例如

8.出现如下警告

9.showSnackBar报错误

解决方案: Scaffold换为ScaffoldMessenger

10.textSelectionColor弃用

解决方案:

11.charts_flutter升级后属性报错

解决方案:

12.flutter 真机调试无法访问网络,dio报错

解决方案:

android:

ios:

问题12完整参考

自定义Plugin插件,Native和flutter传参相互交互

1 File-New Flutter Project -Flutter-next选择 project type(Android studio不同版本会有所差异)

参考链接:

2.1本地引入

这里plugin是flutter module引入使用,如果想project引用其实可以直接在.android下面创建插件

2.2远程引用

flutter 反编译

You are building a fat APK that includes binaries for android-arm, android-arm64.

If you are deploying the app to the Play Store, it's recommended to use app bundles or split the APK to reduce the APK size.

To generate an app bundle, run:

    flutter build appbundle --target-platform android-arm,android-arm64

    Learn more on:

To split the APKs per ABI, run:

    flutter build apk --target-platform android-arm,android-arm64 --split-per-abi

    Learn more on: 

Initializing gradle...                                              2.3s

Resolving dependencies...                                          14.2s

Running Gradle task 'assembleRelease'...                                                  ע: E:\work_tool\flutter\.pub-cache\hosted\pub.flutter-io.cn\connectivity-0.4.4\android\src\main\java\io\flutter\plugins\connectivity\ConnectivityPlugin.javaʹ�û????����ѹ�ʱ�� API��

ע: �й���ϸ��Ϣ, ��ʹ�� -Xlint:deprecation ���±��롣

ע: E:\work_tool\flutter\.pub-cache\hosted\pub.flutter-io.cn\url_launcher-5.1.3\android\src\main\java\io\flutter\plugins\urllauncher\WebViewActivity.javaʹ

�û????����ѹ�ʱ�� API��

ע: �й���ϸ��Ϣ, ��ʹ�� -Xlint:deprecation ���±��롣

Calling mockable JAR artifact transform to create file: C:\Users\Administrator\.gradle\caches\transforms-1\files-1.1\android.jar\baf414ed95f14e507d85c560886dfbe2\android.jar with input E:\work_tool\sdk\android-sdk-windows\platforms\android-28\android.jar

Calling mockable JAR artifact transform to create file: C:\Users\Administrator\.gradle\caches\transforms-1\files-1.1\android.jar\ab096bb3fb172ccb785acdb1058c10a9\android.jar with input E:\work_tool\sdk\android-sdk-windows\platforms\android-27\android.jar

Request to incrementing alive workforce from 0. Current workforce (dead or alive) 0

thread-pool size=4

ProGuard, version 6.0.3

Reading input...

Reading program jar [C:\Users\Administrator\.gradle\caches\transforms-1\files-1.1\flutter.jar\ab2691c929f4d2aa57a17fa551e662a6\jetified-flutter.jar] (filtered)

Reading program jar [F:\dartSpace\flutter\jiddspace\nfc\build\app\intermediates\flutter\release\libs.jar] (filtered)

Reading program jar [C:\Users\Administrator\.gradle\caches\transforms-1\files-1.1\localbroadcastmanager-1.0.0.aar\7a407f962902eada026a8e241a760bac\jars\classes.jar] (filtered)

Reading program jar [C:\Users\Administrator\.gradle\caches\transforms-1\files-1.1\work-runtime-2.1.0.aar\8e3a1e8a8ff79006a94df6c01ceeb4f5\jars\classes.jar] (filtered)

Reading program jar [C:\Users\Administrator\.gradle\caches\transforms-1\files-1.1\fragment-1.1.0.aar\4fa7d1b49e3514cb08c8a696f9b59436\jars\classes.jar] (filtered)

Reading program jar [C:\Users\Administrator\.gradle\caches\transforms-1\files-1.1\room-runtime-2.1.0.aar\1b8774fa39759f08defb930275652eac\jars\classes.jar] (filtered)

Reading program jar [C:\Users\Administrator\.gradle\caches\transforms-1\files-1.1\room-runtime-2.1.0.aar\1b8774fa39759f08defb930275652eac\jars\libs\room-common-java8-2.1.0.jar] (filtered)

Reading program jar [C:\Users\Administrator\.gradle\caches\transforms-1\files-1.1\viewpager-1.0.0.aar\885186e7f6f969363bc93cd607d741a5\jars\classes.jar] (filtered)

Reading program jar [C:\Users\Administrator\.gradle\caches\transforms-1\files-1.1\loader-1.0.0.aar\f84f22ad0a97d2c689850b912fc04277\jars\classes.jar] (filtered)

Reading program jar [C:\Users\Administrator\.gradle\caches\transforms-1\files-1.1\activity-1.0.0.aar\a46db1490fae1b9001fc672a24eb288f\jars\classes.jar] (filtered)

Reading program jar [C:\Users\Administrator\.gradle\caches\transforms-1\files-1.1\customview-1.0.0.aar\fe8bf4a709414e884086911d2168b715\jars\classes.jar] (filtered)

Reading program jar [C:\Users\Administrator\.gradle\caches\transforms-1\files-1.1\core-1.1.0.aar\87febb54759dd5a2c7be8e971d745644\jars\classes.jar] (filtered)

Reading program jar [C:\Users\Administrator\.gradle\caches\transforms-1\files-1.1\versionedparcelable-1.1.0.aar\754157c6f50ca4e4cf3ac8d7cb5ced26\jars\classes.jar] (filtered)

Reading program jar [C:\Users\Administrator\.gradle\caches\modules-2\files-2.1\androidx.collection\collection\1.1.0\1f27220b47669781457de0d600849a5de0e89909\collection-1.1.0.jar] (filtered)

Reading program jar [C:\Users\Administrator\.gradle\caches\transforms-1\files-1.1\lifecycle-livedata-2.0.0.aar\de6944801d37d99b1dd0b877649fde1f\jars\classes.jar] (filtered)

Reading program jar [C:\Users\Administrator\.gradle\caches\transforms-1\files-1.1\lifecycle-livedata-core-2.0.0.aar\e21d6663beb6faa41a30fd5a582cb4d9\jars\classes.jar] (filtered)

Reading program jar [C:\Users\Administrator\.gradle\caches\transforms-1\files-1.1\core-runtime-2.0.1.aar\724bb0cc2ce99eaf0a23a99bb1cc5c23\jars\classes.jar] (filtered)

Reading program jar [C:\Users\Administrator\.gradle\caches\modules-2\files-2.1\androidx.room\room-common\2.1.0\b87765704590bd992ea0d92ac50253a9df7818a0\room-common-2.1.0.jar] (filtered)

Reading program jar [C:\Users\Administrator\.gradle\caches\transforms-1\files-1.1\sqlite-framework-2.0.1.aar\9cbdf82e938f7e565620a3682d2406e9\jars\classes.jar] (filtered)

Reading program jar [C:\Users\Administrator\.gradle\caches\transforms-1\files-1.1\sqlite-2.0.1.aar\1215aa5476f752bd431fb2d8059a1a39\jars\classes.jar] (filtered)

Reading program jar [C:\Users\Administrator\.gradle\caches\transforms-1\files-1.1\lifecycle-service-2.0.0.aar\9d24ebd4d6766d7b2cd515369a737934\jars\classes.jar] (filtered)

Reading program jar [C:\Users\Administrator\.gradle\caches\transforms-1\files-1.1\lifecycle-runtime-2.1.0.aar\ca02c0867547ae607130bcc54a4a9ba5\jars\classes.jar] (filtered)

Reading program jar [C:\Users\Administrator\.gradle\caches\transforms-1\files-1.1\lifecycle-viewmodel-2.1.0.aar\594e1ff6298a01d8933530bb534fa472\jars\classes.jar] (filtered)

Reading program jar [C:\Users\Administrator\.gradle\caches\transforms-1\files-1.1\savedstate-1.0.0.aar\8a2c3791a34fc80e5d9d268bf2886f95\jars\classes.jar] (filtered)

Reading program jar [C:\Users\Administrator\.gradle\caches\modules-2\files-2.1\androidx.lifecycle\lifecycle-common\2.1.0\c67e7807d9cd6c329b9d0218b2ec4e505dd340b7\lifecycle-common-2.1.0.jar] (filtered)

Reading program jar [C:\Users\Administrator\.gradle\caches\modules-2\files-2.1\androidx.arch.core\core-common\2.1.0\b3152fc64428c9354344bd89848ecddc09b6f07e\core-common-2.1.0.jar] (filtered)

Reading program jar [C:\Users\Administrator\.gradle\caches\modules-2\files-2.1\androidx.annotation\annotation\1.1.0\e3a6fb2f40e3a3842e6b7472628ba4ce416ea4c8\annotation-1.1.0.jar] (filtered)

Reading program jar [C:\Users\Administrator\.gradle\caches\modules-2\files-2.1\com.google.guava\listenablefuture\1.0\c949a840a6acbc5268d088e47b04177bf90b3cad\listenablefuture-1.0.jar] (filtered)

Reading program jar [F:\dartSpace\flutter\jiddspace\nfc\build\flutter_downloader\intermediates\intermediate-jars\release\classes.jar] (filtered)

Reading program jar [F:\dartSpace\flutter\jiddspace\nfc\build\shared_preferences\intermediates\intermediate-jars\release\classes.jar] (filtered)

Reading program jar [F:\dartSpace\flutter\jiddspace\nfc\build\url_launcher\intermediates\intermediate-jars\release\classes.jar] (filtered)

Reading program jar [F:\dartSpace\flutter\jiddspace\nfc\build\sqflite\intermediates\intermediate-jars\release\classes.jar] (filtered)

Reading program jar [F:\dartSpace\flutter\jiddspace\nfc\build\connectivity\intermediates\intermediate-jars\release\classes.jar] (filtered)

Reading program jar [F:\dartSpace\flutter\jiddspace\nfc\build\path_provider\intermediates\intermediate-jars\release\classes.jar] (filtered)

Reading program jar [F:\dartSpace\flutter\jiddspace\nfc\build\package_info\intermediates\intermediate-jars\release\classes.jar] (filtered)

Reading program directory [F:\dartSpace\flutter\jiddspace\nfc\build\app\intermediates\javac\release\compileReleaseJavaWithJavac\classes] (filtered)

Reading program jar [F:\dartSpace\flutter\jiddspace\nfc\build\app\intermediates\transforms\mergeJavaRes\release\0.jar] (filtered)

Reading library jar [C:\Users\Administrator\.gradle\caches\modules-2\files-2.1\androidx.annotation\annotation\1.0.0\45599f2cd5965ac05a1488fa2a5c0cdd7c499ead\annotation-1.0.0.jar] (filtered)

Reading library jar [E:\work_tool\sdk\android-sdk-windows\platforms\android-28\android.jar]

Reading library jar [E:\work_tool\sdk\android-sdk-windows\build-tools\28.0.3\core-lambda-stubs.jar]

Reading library jar [E:\work_tool\sdk\android-sdk-windows\platforms\android-28\optional\org.apache.http.legacy.jar]

Reading library jar [E:\work_tool\sdk\android-sdk-windows\platforms\android-28\optional\android.test.mock.jar]

Reading library jar [E:\work_tool\sdk\android-sdk-windows\platforms\android-28\optional\android.test.base.jar]

Reading library jar [E:\work_tool\sdk\android-sdk-windows\platforms\android-28\optional\android.test.runner.jar]

Initializing...

Warning: io.flutter.embedding.android.FlutterView: can't find referenced method 'android.graphics.Insets getSystemGestureInsets()' in library class android.view.WindowInsets

Warning: io.flutter.embedding.android.FlutterView: can't find referenced class android.graphics.Insets

Warning: io.flutter.embedding.android.FlutterView: can't find referenced class android.graphics.Insets

Warning: io.flutter.embedding.android.FlutterView: can't find referenced class android.graphics.Insets

Warning: io.flutter.embedding.android.FlutterView: can't find referenced class android.graphics.Insets

Warning: io.flutter.embedding.android.FlutterView: can't find referenced class android.graphics.Insets

Warning: io.flutter.embedding.android.FlutterView: can't find referenced class android.graphics.Insets

Warning: io.flutter.view.FlutterView: can't find referenced method 'android.graphics.Insets getSystemGestureInsets()' in library class android.view.WindowInsets

Warning: io.flutter.view.FlutterView: can't find referenced class android.graphics.Insets

Warning: io.flutter.view.FlutterView: can't find referenced class android.graphics.Insets

Note: io.flutter.view.AccessibilityViewEmbedder$ReflectionAccessors: can't find dynamically referenced class android.util.LongArray

Warning: io.flutter.view.FlutterView: can't find referenced class android.graphics.Insets

Warning: io.flutter.view.FlutterView: can't find referenced class android.graphics.Insets

Warning: io.flutter.view.FlutterView: can't find referenced class android.graphics.Insets

Warning: io.flutter.view.FlutterView: can't find referenced class android.graphics.Insets

Note: there were 1 unresolved dynamic references to classes or interfaces.

  You should check if you need to specify additional program jars.

  ()

Warning: Exception while processing task java.io.IOException: Please correct the above warnings first.

Thread(Tasks limiter_1): destruction

Warning: there were 12 unresolved references to classes or interfaces.

    You may need to add missing library jars or update their versions.

    If your code works fine without the missing classes, you can suppress

    the warnings with '-dontwarn' options.

    ()

Warning: there were 2 unresolved references to library class members.

    You probably need to update the library versions.

    ()

FAILURE: Build failed with an exception.

* What went wrong:

Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.

Job failed, see logs for details

* Try:

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at

BUILD FAILED in 4m 23s

Running Gradle task 'assembleRelease'...

Running Gradle task 'assembleRelease'... Done                    264.4s (!)

*******************************************************************************************

The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app.

See for more information on the problem and how to fix it.

*******************************************************************************************

Gradle task assembleRelease failed with exit code 1

Flutter开发--Pub包管理

在原生开发中, Android 使用 Gradle 来管理依赖, iOS 用 Cocoapods 来管理依赖,Node 中通过 npm来管理依赖。 Flutter 使用配置文件 pubspec.yaml (位于项目根目录)来管理第三方依赖包。

Pub 是Google官方的Dart Packages仓库,类似于node中的npm仓库,android中的jcenter,我们可以在上面查找我们需要的包和插件,也可以向pub发布我们的包和插件。

Pub工具 包含管理Package、部署Package和部署命令行应用的命令。

如果使用的是Flutter SDK,不要直接使用pub命令。而是使用flutter pub命令,如下:

命令pub get/upgrade/outdated 属于管理Package的依赖关系

用于检索当前 Package 所依赖的其它 Package。如果 pubspec.lock 文件已经存在,则根据该文件中保存的依赖项版本获取对应的依赖项。如有必要,将会创建或更新该文件。

更新 package 依赖

当你添加一个 package 后首次运行 flutter pub get, Flutter 将会保存在 pubspec.lock lockfile 中找到的具体 package 版本。这将确保当你或者团队中其他开发者运行 flutter pub get 后能得到相同版本的 package。

如果你想升级到 package 的最新版本,比如使用 package 的最新特性,请运行 flutter pub upgrade 。这将检索你在 pubspec.yaml 文件中指定的版本约束所允许的最高可用版本。

案例

在flutter项目中导入hive包,在pubspec.yaml文件中添加配置:

执行flutter pub get,可以在 pubspec.lock 中看到 hive 版本是2.1.0,这是因为目前hive的最新版本是2.1.0,配置“^”表示向最新版本兼容,具体可查看Package版本管理( ),所以再执行flutter pub upgrade 可以看到版本还是2.1.0,这个时候会发现pub get和 pub upgrade 效果一样。

但是未来如果 hive 发布了2.2.0版本,这个时候使用flutter pub get在pubspec.lock中看到hive版本依旧是2.1.0,而执行flutter pub upgrade 后在pubspec.lock中看到hive版本就是2.2.0。

现在先在flutter 项目的pubspec.yaml文件添加配置,指定hive版本是2.0.5,如下:

这个时候执行flutter pub get后,可以在pubspec.lock的文件中看到hive版本是2.0.5,如果这个时候更改配置为 hive: ^2.0.5,再执行flutter pub get就会发现在pubspec.lock的文件中看到hive版本还是2.0.5,这个时候可以执行flutter pub outdated查看依赖的每个 package,如下图,

可以看到,Upgrable项hive版本号为2.1.0,执行flutter pub upgrade 后可以看到在pubspec.lock的文件中看到hive版本是2.1.0

在pubspec.yaml文件添加配置:

lxx_package_demo信息如下图:

执行flutter pub get后在pubspec.lock中看到flutter_log版本是0.0.1

现在修改lxx_package_demo版本号为0.0.2,再执行flutter pub get

会发现版本会及时更新为0.0.2,这个时候执行flutter pub get/upgrade效果一样

参考文档:

【百度地图篇】1.Flutter+百度Sdk实现地图功能 & 百度地图显示网格问题

我是初学者小白,所以很多看法不深,理解也不够透彻。但是很适合小白们一起从低角度往高处探索。文中有错误的,感谢指正,一起进步。

趁着假期做一个Flutter的地图功能,因为后端选用了百度地图,所以前端没得挑。找了遍插件,并没有现成可用的。(不过发现了百度官方也自开发Flutter插件,目前功能只有一个获取本地位置信息,后期会继续增加吧?很期待!)

参考帖子:

这个实际上跟功能之间没太大关系,只是我按照个人摸索的过程来写。

当对一个“领域/知识块”完全不懂的时候,360°的方向都不确定的话。先了解基础概念,有利于你确定自己的摸索方向。

参考帖子:

中间我跳过了几十,上百个帖子的摸索过程。这个才是关键能够真正做事的参考。

因为百度的sdk还算是很完善的,所以一旦出问题,都会有对应的报错提示。

我是使用flutter插件:permission_handler,来解决安卓的动态授权问题,用法简单而且设计合理。

这个错误直接来看,就是签名有问题。怎么查看SHA1码和包名,这里不多说,网上有极其多的方法,百度Sdk开发指南里也有。没那么复杂,也没那么麻烦。按照流程操作就是对的。

实在不放心?跟我一样,flutter打包后,把apk反过来解SHA1码不就行了?

参考帖子:

红色框框基本就是帖子讲解的那样。

蓝色框框见下图:release标签里好像是自己设置了。所以debug标签里面,箭头指向的位置,是我多设置的一个参数。

uid: -1 appid -1 msg: httpsPost failed,IOException:Unable to resolve host "api.map.baidu.com": No address associated with hostname

这一步我是哭笑不得,一开始老是和问题(2)混淆,导致浪费很多时间。仔细阅读后,发现是不能连接到“api.map.baidu.com”。

我打开模拟器的chrome浏览器,发现不能上网。查看手机的dns是10.0.2.3(默认的),和家里wifi不一样,所以不能上网也正常,之前居然没发现这个问题!!!

终端执行:adb shell  和  getprop,就可以查看所有的属性参数了。(window小伙伴自行百度,这个没多大差别。如果你有多个设备,记得自己选好设备。)

在里面找到这一项,就是你的dns参数。有些人是net.dns1,我的是net.eth0.dns1。这个没关系,只是等下指令 稍微改动 就行。

修改dns指令:setprop net.eth0.dns1 192.168.2.1

后面的192.168.2.1是我自己的dns,这个根据自己的情况来填写。不懂的百度下怎么查看自己的dns。

虽然提示设置失败,但是回到模拟器一看,地图已经显示出来了。

嘿嘿,在flutter设定多大的区域,地图就是多大的区域。用起来就很方便了。

过程十分痛苦,因为对flutter不是很熟悉,对Android原生更是了解很少。所以自己就像突然不能讲话,被丢到一个陌生的环境,却要我去找一个人。所以细心很重要,一定要看清楚错误提示,不要错过每一个细节和可能性。

幸好最后解决了问题,开心~

其实如果你仔细阅读过百度官方的文档,会发现里面有关于 地图的生命周期管理 。然后在这里面没有提及到,这一点虽然没提,但不可或缺,小伙伴就自行思考吧。

最后还有一点,其实我的初衷是想实现一个百度地图的plugin,但是苦于能力有限,对Android的不熟悉,最后折戟。我不得已另起项目,然后重新实现地图sdk接入。经过这次对于这些有更多更全面的认知后,有空会再次研究flutter 插件的开发,共勉,奥利给!!!


本文标题:flutter2.1,flutter210键盘问题
文章出自:http://cdxtjz.cn/article/dsigssp.html

其他资讯