flutter2.1升级flutter3.0

这篇具有很好参考价值的文章主要介绍了flutter2.1升级flutter3.0。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

  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<PermissionGroup, PermissionStatus> 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
<!-- <meta-data
              android:name="io.flutter.embedding.android.SplashScreenDrawable"
              android:resource="@drawable/launch_background"
              /> --> 注释掉
  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.PlatformViewsChannel 1. 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.MethodChannel 1.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$dispatchMessageToQueue 0 0 0io-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.RuntimeInit ExternalSyntheticLambda0.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,还有一些包的更新,如下

pubspec.yml
	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
	#相册
	barcode_scan2: ^4.0.1

编译时提示如下,修改为gradle对应版本文章来源地址https://www.toymoban.com/news/detail-406302.html

┌─ Flutter Fix ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ 
│ [!] Your project requires a newer version of the Kotlin Gradle plugin.                                                                                │ 
│ Find the latest version on https://kotlinlang.org/docs/gradle.html#plugin-and-versions, then update E:\code\flutter\webview_app\android\build.gradle: │ 
│ ext.kotlin_version = '<latest-version>'                                                                                                               │ 
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ 
build.gradle

buildscript {
    ext.kotlin_version = '1.7.10'
    dependencies {
        classpath 'com.android.tools.build:gradle:7.2.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

到了这里,关于flutter2.1升级flutter3.0的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 修改Flutter3.19.2SDK的镜像源为国内镜像源 解决一直卡在Running Gradle task ‘assembleDebug‘与Executfailed for task ‘app:x‘

    该文档仅为个人解决记录 参考自:https://blog.csdn.net/qq_39105508/article/details/133992154 在 flutter3.19.2packagesflutter_toolslibsrc 下的 http_host_validator.dart 文件中,找到 const String kMaven = \\\'https://maven.google.com/\\\'; ,将 Flutter SDK 使用的 maven 镜像修改为国内镜像 参考自:https://blog.csdn.net/libra_

    2024年04月17日
    浏览(46)
  • GeoScene Pro 2.1下载地址与安装基本要求

    GeoScene Pro 2.1下载地址与安装基本要求 一、软件安装介质下载地址 链接:链接: https://pan.baidu.com/s/1cO3vIxvx7Y0oS1hKS3Bx1Q 提取码:fkng 以上是GeoScene Pro 2.1的下载地址 提示:不要安装在根目录下,不要安装在桌面,不要安装在移动硬盘 二、软件安装的软硬件及系统基本要求 在虚拟

    2024年02月07日
    浏览(24)
  • flutter升级、降级操作步骤

    打开运行终端 直接输入 flutter upgrade 版本号 需要先确定想要降级的版本号。 切换到系统安装flutter的目录 在https://github.com/flutter/flutter,找到要回退的版本号对应的commit序号(具体查找方法如图) 终端执行git reset —hard commitId 再执行flutter doctor 此时就已经降级成功了 可以执行

    2024年02月02日
    浏览(45)
  • 强大的Flutter App升级功能

    注意:无特殊说明,Flutter版本及Dart版本如下: Flutter版本: 1.12.13+hotfix.5 Dart版本: 2.7.0 应用程序升级功能是App的基础功能之一,如果没有此功能会造成用户无法升级,应用程序的bug或者新功能老用户无法触达,甚至损失这部分用户。 对于应用程序升级功能的重要性就无需赘

    2024年04月15日
    浏览(33)
  • Flutter应用-使用sqflite升级数据库

    使用fluttter开发的应用程序发布后,发现数据库有些设计不合理。如何来更新数据库呢? 使用sqflite来处理数据库,但是第一版软件发布后,发现数据库不太合理要改动,想新的应用安装启动后更新数据库。 下面以将一张表名称叫timerdata的表在新版应用启动时将这张表的名称

    2024年02月05日
    浏览(29)
  • Flutter 本地SQLite数据库版本升级处理

    前言 上一篇我们介绍了使用 sqflite 这个数据库工具在 Flutter 的应用中建立本地数据库的实例应用。了解过数据库的同学应该会知道,数据表结构是可能发生改变的。但是 App 的版本会有碎片化的存在,如果数据表结构发生了改变,就需要对旧版本 App 的数据表结构进行同步,

    2023年04月09日
    浏览(29)
  • OpenSSH 漏洞修复升级最新版本

    Centos7系统ssh默认版本一般是OpenSSH7.4左右,低版本是有漏洞的而且是高危漏洞,在软件交付和安全扫描上是过不了关的,一般情况需要升级OpenSSH的最新版本 今天详细说下升级最新版本的处理过程(认真看会发现操作很简单,因为写的操作很详细...) 现在绝大多数服务器的操

    2024年01月22日
    浏览(35)
  • flutter android studio升级java java17

    oricle 网站下载jdk 17 sudo dpkg -i 安装包。 到android-studio 目录, 更新.bashrc里面 然后运行flutter doctor

    2024年04月28日
    浏览(37)
  • Flutter最新稳定版3.16 新特性介绍

    Flutter 3.16 默认采用 Material 3 主题,Android 平台预览 Impeller,DevTools 扩展等等 欢迎回到每季度一次的 Flutter 稳定版本发布,这次是 Flutter 3.16。这个版本将 Material 3 设为新的默认主题,为 Android 带来 Impeller 预览,支持为 DevTools 添加扩展等等!与此同时,我们还看到了Flutter Cas

    2024年02月04日
    浏览(29)
  • springboot升级到jdk21最新教程

    1.1 POM文件 最近很多小伙伴私信我要我出一个springboot搭配jdk21的教程,应粉丝要求,我去spring官网找到了springboot和jdk版本的是配图,供大家参考!之前博主写的springboot 3.0.0 搭配jdk20不知道各位小伙伴们有没有看过呢?现在jdk21出来了,springboot 3.0.0的版本已经不够用了,需要升

    2024年02月08日
    浏览(35)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包