IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 移动开发 -> Upgrade flutter2.1 to flutter3.0 -> 正文阅读

[移动开发]Upgrade flutter2.1 to 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,还有一些包的更新,如下

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

  移动开发 最新文章
Vue3装载axios和element-ui
android adb cmd
【xcode】Xcode常用快捷键与技巧
Android开发中的线程池使用
Java 和 Android 的 Base64
Android 测试文字编码格式
微信小程序支付
安卓权限记录
知乎之自动养号
【Android Jetpack】DataStore
上一篇文章      下一篇文章      查看所有文章
加:2022-09-04 01:23:00  更:2022-09-04 01:26:09 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/25 4:33:01-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码