首页 > 其他分享 >flutter_ohos_原生和flutter交互跳转

flutter_ohos_原生和flutter交互跳转

时间:2024-12-18 09:32:52浏览次数:6  
标签:Index Log void 跳转 ohos flutter flutterEntry

flutter_ohos_原生和flutter交互跳转

1. EntryAbility 可以继承 UIAbility

export default class EntryAbility extends UIAbility implements ExclusiveAppComponent<UIAbility> {

  detachFromFlutterEngine(): void {
    // throw new Error('Method not implemented.');
  }

  getAppComponent(): UIAbility {
    return this;
  }

  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
    FlutterManager.getInstance().pushUIAbility(this);
  }

  onDestroy(): void | Promise<void> {
    FlutterManager.getInstance().popUIAbility(this);
  }

  onWindowStageCreate(windowStage: window.WindowStage): void {
    windowStage.getMainWindowSync().setWindowLayoutFullScreen(true);
    FlutterManager.getInstance().pushWindowStage(this, windowStage);
    windowStage.loadContent('pages/Index');
  }

  onWindowStageDestroy() {
    FlutterManager.getInstance().popWindowStage(this);
  }
}

2. 继承 FlutterEntry 并注册插件

export default class MyFlutterEntry extends FlutterEntry {
  configureFlutterEngine(flutterEngine: FlutterEngine): void {
    super.configureFlutterEngine(flutterEngine);
    GeneratedPluginRegistrant.registerWith(flutterEngine);
    this.delegate?.addPlugin(new BatteryPlugin());
  }
}

3. FlutterEntry 需要和 FlutterView 一起使用

@Entry
@Component
struct Index {
  private flutterEntry: FlutterEntry | null = null;
  private flutterView?: FlutterView

  aboutToAppear() {
    Log.d("Flutter", "Index aboutToAppear===");
    this.flutterEntry = new MyFlutterEntry(getContext(this))
    this.flutterEntry.aboutToAppear()
    this.flutterView = this.flutterEntry.getFlutterView()
  }

  aboutToDisappear() {
    Log.d("Flutter", "Index aboutToDisappear===");
    this.flutterEntry?.aboutToDisappear()
  }

  onPageShow() {
    Log.d("Flutter", "Index onPageShow===");
    this.flutterEntry?.onPageShow()
  }

  onPageHide() {
    Log.d("Flutter", "Index onPageHide===");
    this.flutterEntry?.onPageHide()
  }

  build() {
    Stack() {
      FlutterPage({ viewId: this.flutterView?.getId() })
      Button('跳转页面2')
        .onClick(() => {
          try {
            router.pushUrl({ url: 'pages/Index2', params: { route: '/second' } })
          } catch (err) {
            Log.d("Flutter", "跳转页面2 error ===" + JSON.stringify(err));
          }
        })
    }
  }
}

标签:Index,Log,void,跳转,ohos,flutter,flutterEntry
From: https://www.cnblogs.com/hongmengos/p/18613899

相关文章

  • flutter_ohos_sequence
    性能分析第一步-梳理线程顺序Flutter应用在性能分析的时候,需要使用分析工具去抓取应用的trace,并对trace进行分析。Flutter应用在渲染流程上与几个线程密不可分,而这篇指南里,主要介绍这几个密不可分的线程,以及它们在渲染流程上顺序。分析工具常用的分析工具有DevEcoStudioProfi......
  • Flutter OHOS fluttertpc_screenshot_callback
    screenshot_callback监听系统截图注意事项Android需要获取存储权限才能正常使用需要真机才能验证截图Flutter中使用注意如果在flutter中重写didChangeAppLifecycleState,其中在三星手机上,侧面截图功能会执行resumed生命周期。caseAppLifecycleState.resumed://应用程......
  • Flutter OHOS fluttertpc_device_util
    fluttertpc_device_util鸿蒙设备工具类Flutter代码调用创建通道staticconstMethodChannel_channel=constMethodChannel('device_util');获取versionname///TheversionnameofthisapplicationstaticFuture<StringgetversionNameasync{finalString......
  • Flutter OHOS flutter_native_image
    flutter_native_image原生Flutter图片工具此插件旨在提供原生工具来调整图像大小并通过压缩降低其质量。代码有点粗糙(尤其是iOS部分),但它可以满足我的需求,并且从未崩溃过。如果您愿意,请随意改进它。用法安装在依赖项下的pubspec.yaml中添加以下几行flutter_native_imag......
  • Flutter OHOS flutter_gpu_image(图片视频添加滤镜)
    GPUImageforFlutterFlutter中相机、照片、视频添加各种滤镜效果。本地环境[✓]Flutter(Channelstable,3.0.0,onmacOS12.3.121E258darwin-x64,localezh-Hans-CN)[✓]AndroidtoolchaindevelopforAndroiddevices(AndroidSDKversion33.0.0-rc1)[✓]Xcod......
  • 鸿蒙Flutter怎样调试dart代码
    鸿蒙Flutter怎么样调试dart代码ets代码使用DevEco-Studio进行调试。dart代码可以使用vscode和AndroidStudio进行调试。flutter鸿蒙化版本调试时,需要加上参数,如:--local-engine=/Users/xxx/ohos/engine/src/out/ohos_debug_unopt_arm64使用vscode调试dart代......
  • 鸿蒙Flutter性能调优之性能分析定界
    鸿蒙Flutter性能调优之性能分析定界flutter鸿蒙化的工程,也可以使用devtools对Dart代码进行调试.前置条件OpenHarmonyNext系统前台运行Flutter页面分析工具DevEcoStudioProfilerSmartPerfFlutter线程介绍Flutter使用多个线程来完成其必要的工作,图层中仅展示了其中两......
  • 鸿蒙Flutter环境相关问题解决方法
    鸿蒙Flutter环境相关问题建议使用的开发工具版本flutter3.7.12-ohos版本python3.8-python3.11java17node18ohpm1.6+HamonyOSSDKapi11Xcode14.3断网环境flutterpubget执行失败解决方案:加上--offline参数,完整命令flutterpubget--offlinemac环境releas......
  • harmony_flutter_udid
    harmony_flutter获取udidUDID说明:在恢复出厂设置后,UDID(唯一设备标识符)可能会发生变化!另外,如果设备通过OTA(在线更新)升级到了Android8.0,并且应用程序被重新安装了,由于Android8.0的安全性更改,UDID也可能会改变。对于已经获取root权限或越狱的设备,其ID是可以被更改的,请注意这一点......
  • harmony_flutter_FlutterEngineGroup
    harmony_flutter_FlutterEngineGroup介绍1.EntryAbility修改为继承自UIAbilityexportdefaultclassEntryAbilityextendsUIAbilityimplementsExclusiveAppComponent<UIAbility>{detachFromFlutterEngine():void{//thrownewError('Methodnotimplem......