热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

flutter2.1升级flutter3.0

下载最新fluttert版本forgithub

  1. 下载最新fluttert版本 for github

  2. 升级kotlin版本 及 gradle版本

Module was compiled with an
incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.
Failed to apply plugin ‘kotlin-android’.
[ +4 ms] > The current Gradle version 6.7 is not compatible with the Kotlin Gradle plugin. Please use Gradle 6.7.1 or newer, or the previous version of the Kotlin plugin

更改build.gradle

buildscript {
ext.kotlin_version = '1.7.10' //改为更新版本
...
repositories {
maven{ url 'https://maven.aliyun.com/nexus/content/groups/public/'} //改为https
...
dependencies {
classpath 'com.android.tools.build:gradle:7.2.0' //改为更新版本
...

更改gradle-wrapper.properties

distributiOnUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip //改为更新版本

  1. 升级gradle后,需要更改maven下载源

Using insecure protocols with repositories, without explicit opt-in, is unsupported. Switch Maven repository ‘maven(http://maven.aliyun.com/nexus/content/groups/public/)’ to redirect to asecure protocol (like HTTPS) or allow insecure protocols. See
https://docs.gradle.org/7.3.3/dsl/org.gradle.api.artifacts.repositories.UrlArtifactRepository.html#org.gradle.api.artifacts.repositories.UrlArtifactRepository:allowInsecureProtocol for more details.

Could not resolve all dependencies for configuration ‘:app:debugRuntimeClasspath’
[ ] > Using insecure protocols with repositories, without explicit opt-in, is unsupported. Switch Maven repository ‘maven(http://maven.aliyun.com/nexus/content/groups/public)’ to redirect to a secure
protocol (like HTTPS) or allow insecure protocols. See

Could not resolve all dependencies for configuration ‘:adv_camera:androidApis’.
[ ] > Using insecure protocols with repositories, without explicit opt-in, is unsupported. Switch Maven repository ‘maven(http://maven.aliyun.com/nexus/content/groups/public)’ to redirect to a secure
protocol (like HTTPS) or allow insecure protocols. See
https://docs.gradle.org/7.3.3/dsl/org.gradle.api.artifacts.repositories.UrlArtifactRepository.html#org.gradle.api.artifacts.repositories.UrlArtifactRepository:allowInsecureProtocol for more details.

$ vi ${flutterRoot}\packages\flutter_tools\gradle\flutter.gradle
maven(http://maven.aliyun.com/nexus/content/groups/public/)
改为
maven(https://maven.aliyun.com/nexus/content/groups/public/)

  1. 修改pubspec.yml sdk版本
    支持null safe的flutter最低版本是2.0.0,对应的dart sdk是2.12.0

environment:
sdk: ">=2.12.0 <3.0.0" #改为2.12

  1. Gradle 7以后的版本是不可以用compile, 性能不如implementation

problem occurred evaluating project ‘:bluetooth_print’.
[ +1 ms] > Could not find method compile() for arguments [file collection] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

Could not run phased build action using connection to Gradle distribution ‘https://services.gradle.org/distributions/gradle-7.1.1-bin.zip’.
java.io.StreamCorruptedException: invalid type code: 00
invalid type code: 00Java(0)

尝试启动工程后,提示还有一些代码需要更改,一些包的升级以及业务代码中空安全的处理

  1. 一些小部件升级
  2. Scaffold.of(context).showSnackBar(…)

Try correcting the name to the name of an existing method, or defining a method named 'showSnackBar'.
[ ] [ ] Scaffold.of(context).showSnackBar(
[ ] [ ] ^^^^^^^^^^^^

改为
ScaffoldMessenger.of(context).showSnackBar(…)

  1. FlatButton 改为 TextButton
    参照 https://github.com/flutter/plugins/commit/a7dd76950e5b240d2d878504a6f010ef24717e34

Try correcting the name to the name of an existing method, or defining a method named 'FlatButton'.
[ ] [ ] FlatButton(
[ ] [ ] ^^^^^^^^^^

  1. RaisedButton 改为 ElevatedButton

Try correcting the name to the name of an existing method, or defining a method named 'RaisedButton'.
[ ] [ ] child: RaisedButton(
[ ] [ ] ^^^^^^^^^^^^

  1. WillPopScope#onWillPop返回true即退出

WillPopScope(
child: ... ,
onWillPop: () async {
// 点击返回键的操作
if(DateTime.now().difference(lastPopTime) > Duration(seconds: 1)){
lastPopTime = DateTime.now();
_gobackWebView();
}else{
lastPopTime = DateTime.now();
// 退出app
await SystemChannels.platform.invokeMethod('SystemNavigator.pop');
}
return true;
}

改为


WillPopScope(
child: ... ,
onWillPop: () async {
// 点击返回键的操作
if(DateTime.now().difference(lastPopTime) > Duration(seconds: 1)){
lastPopTime = DateTime.now();
_gobackWebView();
return false;
}else{
lastPopTime = DateTime.now();
return true;// 退出app
}
}

  1. AsyncSnapshot获取data
    AsyncSnapshot snapshot

final WebViewController cOntroller= snapshot.requireData;

改为

final WebViewController cOntroller= snapshot.data!;

  1. 更新permission_handler到最新版本,需要用新的方式获取权限

lib/sample.dart:402:11: Error: 'PermissionGroup' isn't a type.
Map permissiOns= await PermissionHandle

  1. 启动报如下错误
    A splash screen was provided to Flutter, but this is deprecated. See flutter.dev/go/android-splash-migration for migration steps

注释掉

  1. 加了allowInsecureProtocol=true, 导致低版本的gradle报错

Launching lib\main.dart on AQM AL00 in debug mode...
Project evaluation failed including an error in afterEvaluate {}. Run with --stacktrace for details of the afterEvaluate {} error.
FAILURE: Build failed with an exception.
* Where:
Script '${flutterRoot}\packages\flutter_tools\gradle\flutter.gradle' line: 187
* What went wrong:
A problem occurred evaluating script.
> Failed to apply plugin [class 'FlutterPlugin']
> Could not set unknown property 'allowInsecureProtocol' for object of type org.gradle.api.internal.artifacts.repositories.DefaultMavenArtifactRepository.

$ vi ${flutterRoot}\packages\flutter_tools\gradle\flutter.gradle
删除 allowInsecureProtocol=true

  1. 打开相机报错 Unexpected platform view context. When constructing a platform view in the factory, use the context from PlatformViewFactory#create, view id: 1

I/PlatformViewsController(24384): Hosting view in a virtual display for platform view: 1
E/flutter (24384): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, java.lang.IllegalStateException: Unexpected platform view context. When constructing a platform view in the factory, use the context from PlatformViewFactory#create, view id: 1
E/flutter (24384): at io.flutter.plugin.platform.SingleViewPresentation.onCreate(SingleViewPresentation.java:187)
E/flutter (24384): at android.app.Dialog.dispatchOnCreate(Dialog.java:874)
E/flutter (24384): at android.app.Dialog.show(Dialog.java:521)
E/flutter (24384): at android.app.Presentation.show(Presentation.java:257)
E/flutter (24384): at io.flutter.plugin.platform.VirtualDisplayController.(VirtualDisplayController.java:119)
E/flutter (24384): at io.flutter.plugin.platform.VirtualDisplayController.create(VirtualDisplayController.java:64)
E/flutter (24384): at io.flutter.plugin.platform.PlatformViewsController$1.createForTextureLayer(PlatformViewsController.java:267)
E/flutter (24384): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:122)
E/flutter (24384): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel1. o n M e t h o d C a l l ( P l a t f o r m V i e w s C h a n n e l . j a v a : 60 ) E / f l u t t e r ( 24384 ) : a t i o . f l u t t e r . p l u g i n . c o m m o n . M e t h o d C h a n n e l 1.onMethodCall(PlatformViewsChannel.java:60) E/flutter (24384): at io.flutter.plugin.common.MethodChannel1.onMethodCall(PlatformViewsChannel.java:60)E/flutter(24384):atio.flutter.plugin.common.MethodChannelIncomingMethodCallHandler.onMessage(MethodChannel.java:261)
E/flutter (24384): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/flutter (24384): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue0 00io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:321)
E/flutter (24384): at io.flutter.embedding.engine.dart.DartMessenger$E x t e r n a l S y n t h e t i c L a m b d a 0. r u n ( U n k n o w n S o u r c e : 12 ) E / f l u t t e r ( 24384 ) : a t a n d r o i d . o s . H a n d l e r . h a n d l e C a l l b a c k ( H a n d l e r . j a v a : 900 ) E / f l u t t e r ( 24384 ) : a t a n d r o i d . o s . H a n d l e r . d i s p a t c h M e s s a g e ( H a n d l e r . j a v a : 103 ) E / f l u t t e r ( 24384 ) : a t a n d r o i d . o s . L o o p e r . l o o p ( L o o p e r . j a v a : 219 ) E / f l u t t e r ( 24384 ) : a t a n d r o i d . a p p . A c t i v i t y T h r e a d . m a i n ( A c t i v i t y T h r e a d . j a v a : 8668 ) E / f l u t t e r ( 24384 ) : a t j a v a . l a n g . r e f l e c t . M e t h o d . i n v o k e ( N a t i v e M e t h o d ) E / f l u t t e r ( 24384 ) : a t c o m . a n d r o i d . i n t e r n a l . o s . R u n t i m e I n i t ExternalSyntheticLambda0.run(Unknown Source:12) E/flutter (24384): at android.os.Handler.handleCallback(Handler.java:900) E/flutter (24384): at android.os.Handler.dispatchMessage(Handler.java:103) E/flutter (24384): at android.os.Looper.loop(Looper.java:219) E/flutter (24384): at android.app.ActivityThread.main(ActivityThread.java:8668) E/flutter (24384): at java.lang.reflect.Method.invoke(Native Method) E/flutter (24384): at com.android.internal.os.RuntimeInitExternalSyntheticLambda0.run(UnknownSource:12)E/flutter(24384):atandroid.os.Handler.handleCallback(Handler.java:900)E/flutter(24384):atandroid.os.Handler.dispatchMessage(Handler.java:103)E/flutter(24384):atandroid.os.Looper.loop(Looper.java:219)E/flutter(24384):atandroid.app.ActivityThread.main(ActivityThread.java:8668)E/flutter(24384):atjava.lang.reflect.Method.invoke(NativeMethod)E/flutter(24384):atcom.android.internal.os.RuntimeInitMethodAndArgsCaller.run(RuntimeInit.java:513)
E/flutter (24384): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1109)

改为官方camera,还有一些包的更新,如下

device_info: ^2.0.3
url_launcher: ^6.1.5
path_provider: ^2.0.11
permission_handler: ^10.0.0
shared_preferences: ^2.0.15
camera: ^0.10.0+1


推荐阅读
  • OpenCV4.5.0+contrib编译流程及解决错误方法
    本文介绍了OpenCV4.5.0+contrib的编译流程,并提供了解决常见错误的方法,包括下载失败和路径修改等。同时提供了相关参考链接。 ... [详细]
  • 本文介绍了在Python3中如何使用选择文件对话框的格式打开和保存图片的方法。通过使用tkinter库中的filedialog模块的asksaveasfilename和askopenfilename函数,可以方便地选择要打开或保存的图片文件,并进行相关操作。具体的代码示例和操作步骤也被提供。 ... [详细]
  • 云原生边缘计算之KubeEdge简介及功能特点
    本文介绍了云原生边缘计算中的KubeEdge系统,该系统是一个开源系统,用于将容器化应用程序编排功能扩展到Edge的主机。它基于Kubernetes构建,并为网络应用程序提供基础架构支持。同时,KubeEdge具有离线模式、基于Kubernetes的节点、群集、应用程序和设备管理、资源优化等特点。此外,KubeEdge还支持跨平台工作,在私有、公共和混合云中都可以运行。同时,KubeEdge还提供数据管理和数据分析管道引擎的支持。最后,本文还介绍了KubeEdge系统生成证书的方法。 ... [详细]
  • 本文介绍了设计师伊振华受邀参与沈阳市智慧城市运行管理中心项目的整体设计,并以数字赋能和创新驱动高质量发展的理念,建设了集成、智慧、高效的一体化城市综合管理平台,促进了城市的数字化转型。该中心被称为当代城市的智能心脏,为沈阳市的智慧城市建设做出了重要贡献。 ... [详细]
  • 本文详细介绍了PHP中与URL处理相关的三个函数:http_build_query、parse_str和查询字符串的解析。通过示例和语法说明,讲解了这些函数的使用方法和作用,帮助读者更好地理解和应用。 ... [详细]
  • baresip android编译、运行教程1语音通话
    本文介绍了如何在安卓平台上编译和运行baresip android,包括下载相关的sdk和ndk,修改ndk路径和输出目录,以及创建一个c++的安卓工程并将目录考到cpp下。详细步骤可参考给出的链接和文档。 ... [详细]
  • MACElasticsearch安装步骤及验证方法
    本文介绍了MACElasticsearch的安装步骤,包括下载ZIP文件、解压到安装目录、启动服务,并提供了验证启动是否成功的方法。同时,还介绍了安装elasticsearch-head插件的方法,以便于进行查询操作。 ... [详细]
  • 【MicroServices】【Arduino】装修甲醛检测,ArduinoDart甲醛、PM2.5、温湿度、光照传感器等,数据记录于SD卡,Python数据显示,UI5前台,微服务后台……
    这篇文章介绍了一个基于Arduino的装修甲醛检测项目,使用了ArduinoDart甲醛、PM2.5、温湿度、光照传感器等硬件,并将数据记录于SD卡,使用Python进行数据显示,使用UI5进行前台设计,使用微服务进行后台开发。该项目还在不断更新中,有兴趣的可以关注作者的博客和GitHub。 ... [详细]
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • Java验证码——kaptcha的使用配置及样式
    本文介绍了如何使用kaptcha库来实现Java验证码的配置和样式设置,包括pom.xml的依赖配置和web.xml中servlet的配置。 ... [详细]
  • imx6ull开发板驱动MT7601U无线网卡的方法和步骤详解
    本文详细介绍了在imx6ull开发板上驱动MT7601U无线网卡的方法和步骤。首先介绍了开发环境和硬件平台,然后说明了MT7601U驱动已经集成在linux内核的linux-4.x.x/drivers/net/wireless/mediatek/mt7601u文件中。接着介绍了移植mt7601u驱动的过程,包括编译内核和配置设备驱动。最后,列举了关键词和相关信息供读者参考。 ... [详细]
  • 本文介绍了Windows操作系统的版本及其特点,包括Windows 7系统的6个版本:Starter、Home Basic、Home Premium、Professional、Enterprise、Ultimate。Windows操作系统是微软公司研发的一套操作系统,具有人机操作性优异、支持的应用软件较多、对硬件支持良好等优点。Windows 7 Starter是功能最少的版本,缺乏Aero特效功能,没有64位支持,最初设计不能同时运行三个以上应用程序。 ... [详细]
  • phpcomposer 那个中文镜像是不是凉了 ... [详细]
  • UMTS基础知识汇总
    协议框架23G接口UMTS实体EntityNameDescriptionAuCAuthenticationCenterCBCCellBroadcastCenterC-RNCCon ... [详细]
  • 关于对整站进行二级域名的改造
    缘由在此之前,博客的访问地址为https:www.codelabo.cnblog(当然现在页可以访问,因为做了重定向),改造成了目前的https:blog.codelabo.cn, ... [详细]
author-avatar
yngbzl_165
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有