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

flutter_ohos_原生和flutter交互跳转

时间:2024-12-18 14:32:28浏览次数:6  
标签:Index Log void 跳转 Flutter 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,跳转,Flutter,ohos,flutter,flutterEntry
From: https://blog.csdn.net/flfljh/article/details/144559135

相关文章

  • harmony_flutter_更新Flutter插件项目结构
    更新Flutter插件项目结构更新内容flutter插件项目中的ohos目录,将从鸿蒙工程project结构,替换为鸿蒙工程module结构。flutter工程中引用的har文件,统一放到ohos/har目录下。更新后需要删除ohos插件中的旧模块目录。更新步骤以flutter_flutter中的integration_test为例......
  • 鸿蒙Flutter性能调优分析之帧渲染跟踪
    鸿蒙Flutter性能调优性能分析之帧渲染跟踪Flutter应用进行性能分析时,需利用分析工具捕获应用的trace数据,并对其进行分析。鉴于Flutter应用中可能会出现需要单独追踪某帧渲染的情况,如帧率卡顿或帧丢失,本文特介绍了一种针对单帧追踪的方法。分析工具常用的分析工具包括DevEcoStu......
  • harmony_flutter_videoCompress(视频压缩)
    harmony_flutter_videoCompress(视频压缩)一.MethodChannel1.flutter端代码创建MethodChannel交互通道video_compress接收ohos端传递过来的进度finalcompressProgress$=ObservableBuilder<double>();final_channel=constMethodChannel('video_compress');@......
  • Flutter OHOS flutter_console
    flutter_consoleAFlutterConsoleUI项目介绍一个在Flutter端Console可视化的组件,将ConsoleWindow置于页面最顶层,用于调试,输出日志等。安装使用安装步骤简单Demoimport'package:flutter/material.dart';import'dart:async';import'package:flutter_console/flutter_......
  • harmony_flutter_orientation_plugins(监听屏幕状态插件)
    harmony_flutter_orientation(屏幕旋转)flutter端监听鸿蒙手机得屏幕横竖屏切换等各种状态一.MethodChannel1.flutter端代码创建MethodChannel交互通道接收ohos端传递过来状态classOrientationPlugin{staticconst_methodChannel=constMethodChannel('sos......
  • harmony_flutter_keyboard_visibility(监听动态键盘)
    harmony_flutter_keyboard_visibility(监听动态键盘)一.MethodChannel1.flutter端代码创建StreamBuilder监听event接收ohos端传递过来的状态值finalKeyboardVisibilityController?controller;KeyboardVisibilityControllerget_controller=>controller?......
  • harmony_flutter 实现短信发送
    harmony_flutter实现短信发送ohos端建立通import{FlutterPlugin,FlutterPluginBinding}from'@ohos/flutter_ohos/src/main/ets/embedding/engine/plugins/FlutterPlugin';import{MethodCallHandler,MethodResult}from'@ohos/flutter_ohos/src/main/e......
  • harmony_flutter 实现拨打电话功能
    harmony_flutter实现拨打电话功能ohos端建立通importcallfrom'@ohos.telephony.call';import{FlutterPlugin,FlutterPluginBinding}from'@ohos/flutter_ohos/src/main/ets/embedding/engine/plugins/FlutterPlugin';import{MethodCallHandler,Me......
  • flutter_ohos_原生和flutter交互跳转
    flutter_ohos_原生和flutter交互跳转1.EntryAbility可以继承UIAbilityexportdefaultclassEntryAbilityextendsUIAbilityimplementsExclusiveAppComponent<UIAbility>{detachFromFlutterEngine():void{//thrownewError('Methodnotimplemented.�......
  • flutter_ohos_sequence
    性能分析第一步-梳理线程顺序Flutter应用在性能分析的时候,需要使用分析工具去抓取应用的trace,并对trace进行分析。Flutter应用在渲染流程上与几个线程密不可分,而这篇指南里,主要介绍这几个密不可分的线程,以及它们在渲染流程上顺序。分析工具常用的分析工具有DevEcoStudioProfi......