上篇博文记录了升级2.0,主要是null-safely相关。本次升级3.7.10版本。
flutter官网下载最新sdk
安装后的版本
升级插件 终端执行:flutter pub upgrade --major-versions
pub.dev
1、FlatButton被废弃
ElevatedButton(
key: keyx,
style: ButtonStyle(
foregroundColor: MaterialStateProperty.resolveWith<Color>(
// text color
(Set<MaterialState> states) => states.contains(MaterialState.disabled)
? disabledTextColorx
: textColorx,
),
backgroundColor: MaterialStateProperty.resolveWith<Color>(
// background color this is color:
(Set<MaterialState> states) =>
states.contains(MaterialState.disabled) ? disabledColorx : colorx,
),
shape: MaterialStateProperty.all(shapex),
),
onPressed: onPressedx as void Function(),
child: childx);
style:ButtonStyle(backgroundColor: MaterialStateColor.resolveWith((states) => ),shape: MaterialStateProperty.all(value)) ,
2、WhitelistingTextInputFormatter被废弃
解决方案:WhitelistingTextInputFormatter属性替换为:FilteringTextInputFormatter
3、修改compileSdkVersion为33
4、升级kotlin版本,尽可能的最新,不是最新也不能太低
5、 <meta-data android:name="flutterEmbedding" android:value="2" />
加入到application节点
6、打开Android目录,修改jdk版本
7、fluwx插件问题,参考issue
https://github.com/OpenFlutter/fluwx/issues/439
8、flutter_webview_plugin插件不再维护,替换为 webview_flutter: ^4.0.7
使用方式也很简单 参考如下
final WebViewController controller =
WebViewController.fromPlatformCreationParams(params);
// #enddocregion platform_features
controller
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setBackgroundColor(const Color(0x00000000))
..setNavigationDelegate(
NavigationDelegate(
onProgress: (int progress) {
debugPrint('WebView is loading (progress : $progress%)');
},
onPageStarted: (String url) {
debugPrint('Page started loading: $url');
},
onPageFinished: (String url) {
debugPrint('Page finished loading: $url');
},
onWebResourceError: (WebResourceError error) {
debugPrint('''
Page resource error:
code: ${error.errorCode}
description: ${error.description}
errorType: ${error.errorType}
isForMainFrame: ${error.isForMainFrame}
''');
},
onNavigationRequest: (NavigationRequest request) {
if (request.url.startsWith('https://www.youtube.com/')) {
debugPrint('blocking navigation to ${request.url}');
return NavigationDecision.prevent;
}
debugPrint('allowing navigation to ${request.url}');
return NavigationDecision.navigate;
},
),
)
..addJavaScriptChannel(
'Toaster',
onMessageReceived: (JavaScriptMessage message) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(message.message)),
);
},
)
..loadRequest(Uri.parse(widget._html!));
Scaffold(
resizeToAvoidBottomInset: true,
appBar: PreferredSize(
child: SafeArea(
child: _bar(),
),
preferredSize: Size(double.infinity, 60)),
backgroundColor: Colors.white,
body: WebViewWidget(controller: _controller),
// body: WebviewScaffold(
// url: widget._html!,
// ),
// 外层添加一个手势,用于点击空白部分,回收键盘
)
9、flutter_screenutil插件初始化方式变化,demo中ThemeData务必删除,否则TextField输入框焦点和内容会无法显示
ScreenUtilInit(
designSize: const Size(750, 1334),
minTextAdapt: true,
splitScreenMode: true,
builder: (context, child) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'First Method',
// You can use the library anywhere in the app even in theme
theme: ThemeData(
primarySwatch: Colors.blue,
textTheme: Typography.englishLike2018.apply(fontSizeFactor: 1.sp),
),
home: child,
);
},
child: WillPopScope(
10、国家化适配
No instance of S present in the widget tree. Did you add S.delegate in localizationsDelegates?
‘package:duxinguser/generated/l10n.dart’:
Failed assertion: line 44 pos 12: ‘instance != null’
[Solved] Flutter Intl Plugin Error: No instance of S present in the widget tree. Did you add S.delegate in localizationsDelegates?
Change this:
//home: MyHomePage(title: S.of(context).title),
to:
home: MyHomePage(title: S.current.title)
11、ios打包失败,务必在ios目录下面执行pod install
删除podfile
https://github.com/OpenFlutter/fluwx/issues/512
Podfile platform改成12.0或者更高
重启xcode clean
Invalid Pre-Release Train. The train version ‘2.2.7’ is closed for new build submissions With error code STATE_ERROR.VALIDATION_ERROR.90186 for id ec0d0008-b28a-4540-8311-4e172a028be6
修改build版本
12、
Android release打包失败 Execution failed for task compileReleaseJavaWithJavac
修改gradle的依赖jdk版本
继续报错😂
* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin 'com.android.internal.application'.
> Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
You can try some of the following options:
- changing the IDE settings.
- changing the JAVA_HOME environment variable.
- changing `org.gradle.java.home` in `gradle.properties`.
* 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.
按照日志解决方案已经给出,使用简单的是第三种方式。找到路径位置
gradle.properties`文件加入
org.gradle.java.home=/Applications/Android Studio.app/Contents/jre/Contents/Home
最终打包成功😇