flutter由2.0升级至3.7.10的那些坑

上篇博文记录了升级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

最终打包成功😇
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值