FlutterBoost适配Flutter3.38.4版本生成补丁包

Flutter 3.38.4 适配修改总结

1. App Lifecycle 状态变化适配(主要修改)

位置 :lib/src/boost_flutter_binding.dart

  • 重写 handleAppLifecycleStateChanged,适配官方引擎的 App Lifecycle 状态变化
  • 使用 _appLifecycleStateLocked 锁定机制,控制生命周期状态变更
  • 通过 changeAppLifecycleState 方法手动触发生命周期状态变更
22:39:lib/src/boost_flutter_binding.dart 复制代码
  @override
  void handleAppLifecycleStateChanged(AppLifecycleState state) {
    if (_appLifecycleStateLocked) {
      return;
    }
    Logger.log('boost_flutter_binding: '
        'handleAppLifecycleStateChanged ${state.toString()}');
    super.handleAppLifecycleStateChanged(state);
  }

  void changeAppLifecycleState(AppLifecycleState state) {
    if (SchedulerBinding.instance.lifecycleState == state) {
      return;
    }
    _appLifecycleStateLocked = false;
    handleAppLifecycleStateChanged(state);
    _appLifecycleStateLocked = true;
  }

位置 :lib/src/flutter_boost_app.dart

  • 在 _addAppLifecycleStateEventListener 中处理原生端发送的生命周期事件
  • 根据容器数量决定 Flutter 的 resume 和 pause 状态
  • 参考了 Flutter Engine PR #42418 的实现
122:141:lib/src/flutter_boost_app.dart 复制代码
  void _addAppLifecycleStateEventListener() {
    _lifecycleStateListenerRemover = BoostChannel.instance
        .addEventListener(_appLifecycleChangedKey, (key, arguments) {
      // we just deal two situation,resume and pause
      // and 1 is resumed
      // and 4 is paused
      // See https://github.com/flutter/engine/pull/42418 for more details.

      final int? index = arguments["lifecycleState"];

      if (index == AppLifecycleState.resumed.index) {
        BoostFlutterBinding.instance!
            .changeAppLifecycleState(AppLifecycleState.resumed);
      } else if (index == AppLifecycleState.paused.index) {
        BoostFlutterBinding.instance!
            .changeAppLifecycleState(AppLifecycleState.paused);
      }
      return Future<dynamic>.value();
    });
  }

2. 使用 mixin 修饰符

位置 :lib/src/boost_flutter_binding.dart

  • 将 BoostFlutterBinding 改为 mixin,避免破坏用户代码
  • 这是 CHANGELOG 5.0.1 中提到的修改
10:10:lib/src/boost_flutter_binding.dart 复制代码
mixin BoostFlutterBinding on WidgetsFlutterBinding {

3. Android 端命名空间修复

  • 在 Android 端添加了命名空间配置(CHANGELOG 5.0.2 第 2 条)

核心适配原理

Flutter 3.38.4 中官方引擎的 App Lifecycle 状态管理机制发生变化。FlutterBoost 通过:

  1. 拦截并控制 handleAppLifecycleStateChanged 的调用
  2. 根据原生容器数量决定 Flutter 应用的生命周期状态
  3. 使用锁定机制避免与官方引擎的生命周期管理冲突

这些修改确保了 FlutterBoost 在 Flutter 3.38.4 下的正常运行,同时保持了与原生应用生命周期的正确同步。

补丁包地址

FlutterBoost适配Flutter3.38.4版本补丁包

相关推荐
晚霞的不甘11 小时前
Flutter/OpenHarmony 三方库适配实战:google_maps_flutter 地图
flutter·macos·华为·cocoa·harmonyos·1024程序员节
恋猫de小郭15 小时前
Flutter HC 旋转 ANR,而且还和之前的 HCPP 问题类似
android·前端·flutter
恋猫de小郭2 天前
Flutter Perfetto:Dart Heap Sampling 终于要接入 Android 原生内存分析了
android·前端·flutter
程序员老刘2 天前
Flutter版本选择指南:尽早升级3.47.9 | 2026年11月
flutter·ai编程·客户端
恋猫de小郭3 天前
Android Keep Rules 解读,直接影响 Google Play 上架和曝光
android·前端·flutter
恋猫de小郭4 天前
Flutter A2UI 1.0 ,原来的 genui 也正式换成了这一套 SDK 了
android·前端·flutter
LinXunFeng4 天前
A2UI 1.0 详解:让 AI 生成 Flutter 界面,还不怕它乱写
前端·flutter·agent
好的佩奇4 天前
Dart 之元数据与注解
android·flutter·dart
恋猫de小郭7 天前
Jetpack Compose 1.13 发布,憋了这么久终有交代了
android·前端·flutter
好的佩奇7 天前
蓝牙之设备角色与连接
android·flutter·蓝牙