当前位置: 首页 > news >正文

武汉网站建设哪家最好关闭站长工具seo综合查询

武汉网站建设哪家最好,关闭站长工具seo综合查询,深圳制作app,软装设计图效果图Flutter中PlatformView在鸿蒙中的使用 概述在Flutter中的处理鸿蒙端创建内嵌的鸿蒙视图创建PlatformView创建PlatformViewFactory创建plugin,注册platformview注册插件 概述 集成平台视图(后称为平台视图)允许将原生视图嵌入到 Flutter 应用…

Flutter中PlatformView在鸿蒙中的使用

  • 概述
  • 在Flutter中的处理
  • 鸿蒙端
    • 创建内嵌的鸿蒙视图
    • 创建PlatformView
    • 创建PlatformViewFactory
    • 创建plugin,注册platformview
    • 注册插件

概述

集成平台视图(后称为平台视图)允许将原生视图嵌入到 Flutter 应用中,所以你可以通过 Dart 将变换、裁剪和不透明度等效果应用到原生视图。

例如,这使你可以通过使用平台视图直接在 Flutter 应用内部使用鸿蒙中的原生地图。

在Flutter中的处理

首先我们需要再Flutter中创建一个视图,用来加载Ohos平台的view。

import 'dart:async';import 'package:flutter/material.dart';
import 'package:flutter/services.dart';typedef OnViewCreated = Function(CustomViewController);class CustomOhosView extends StatefulWidget {final OnViewCreated onViewCreated;const CustomOhosView(this.onViewCreated, {super.key});State<CustomOhosView> createState() => _CustomOhosViewState();
}class _CustomOhosViewState extends State<CustomOhosView> {late MethodChannel _channel;Widget build(BuildContext context) {return _getPlatformFaceView();}Widget _getPlatformFaceView() {// 加载platformview/*** viewType:传递给Native侧,告知插件需要创建那个PlatformView,这个PlatformView需要在插件初始化时注册。onPlatformViewCreated:PlatformView创建成功时的回调。creationParams:传递给PlatformView的初始化参数。*/return OhosView(viewType: 'com.rex.custom.ohos/customView',onPlatformViewCreated: _onPlatformViewCreated,creationParams: const <String, dynamic>{'initParams': 'hello world'},creationParamsCodec: const StandardMessageCodec(),);}void _onPlatformViewCreated(int id) {print("platformview==================创建成功");_channel = MethodChannel('com.rex.custom.ohos/customView$id');final controller = CustomViewController._(_channel,);widget.onViewCreated(controller);}
}// 用于实现Dart侧与Native侧的交互
class CustomViewController {final MethodChannel _channel;final StreamController<String> _controller = StreamController<String>();CustomViewController._(this._channel,) {_channel.setMethodCallHandler((call) async {switch (call.method) {case 'getMessageFromOhosView':// 从native端获取数据final result = call.arguments as String;_controller.sink.add(result);break;}},);}Stream<String> get customDataStream => _controller.stream;// 发送数据给nativeFuture<void> sendMessageToOhosView(String message) async {await _channel.invokeMethod('getMessageFromFlutterView',message,);}
}

鸿蒙端

创建内嵌的鸿蒙视图

该视图就是我们ohos平台中的组件, 示例代码如下:

@Component
export struct PlatformView_Custom {@Prop params: Params// customView: video_Customview = this.params.platformView as video_Customviewbuild() {Column() {Column() {Button("测试按钮").onClick(() => {console.log("点击按钮时间")})}.backgroundColor(Color.Orange).height('230vp').width('100%').justifyContent(FlexAlign.End)}.backgroundColor(Color.Pink).width('100%').height('100%')}
}

注意:PlatformView_Custom 嵌入到Flutter页面中时, 系统实际上是在我们的这个组件又包裹了一层空间, 并且默认是充满Flutter父空间的全部空间。

创建PlatformView

我们需要创建一个PlatformView的子类,并实现并且实现MethodCallHandler接口。

该类有两个作用:

  1. 通过类中的getView(): WrappedBuilder<[Params]>{}方法把上面创建的鸿蒙组件加载到这个PlatformView上
  2. 实现MethodCallHandler接口, 负责和Flutter的相关通信

示例代码如下:

/*** @ProjectName : ohos* @FileName : PlatformView_plugin* @Author : issuser* @Time : 2024/10/11 9:33* @Description : 文件描述*/
import {BinaryMessenger,MethodCall, MethodCallHandler, MethodChannel, MethodResult, PlatformView,StandardMethodCodec } from '@ohos/flutter_ohos';
import { Params } from '@ohos/flutter_ohos/src/main/ets/plugin/platform/PlatformView';
import { PlatformView_Custom } from './PlatformView_Custom';
import { common } from '@kit.AbilityKit';export class PlatformView_plugin extends PlatformView implements MethodCallHandler {numValue: string = "test";methodChannel: MethodChannel;index: number = 1;// 构造方法constructor(context: common.Context, viewId: number, args: ESObject, message: BinaryMessenger) {super();// 注册消息通道,消息通道根据具体需求添加,代码仅作为示例this.methodChannel = new MethodChannel(message, `com.rex.custom.ohos/video_CustomView${viewId}`, StandardMethodCodec.INSTANCE);// 给通道添加监听this.methodChannel.setMethodCallHandler(this);}// 实现onMethodCall接口onMethodCall(call: MethodCall, result: MethodResult): void {// 接受Dart侧发来的消息let method: string = call.method;let link1: SubscribedAbstractProperty<number> = AppStorage.link('numValue');switch (method) {case 'video_getMessageFromFlutterView':let value: ESObject = call.args;this.numValue = value;link1.set(value)console.log("nodeController receive message from dart: " + this.numValue);result.success(true);break;}}//  返回鸿蒙要展示的视图getView(): WrappedBuilder<[Params]> {return new WrappedBuilder(platformBuilder)}// 生命周期方法 销毁时dispose(): void {throw new Error('Method not implemented.');}}// 全局的build函数,通过这个bbuilder函数返回我们的组件view
@Builder
function platformBuilder(param: Params) {PlatformView_Custom({params: param}).backgroundColor(Color.Green)
}

创建PlatformViewFactory

PlatformView类的创建是通过PlatformViewFactory来创建, 所以我们需要创建一个工厂类继承自PlatformViewFactory

示例代码:

// 通过工厂方法创建一个plaugin示例
export class CustomFactory extends PlatformViewFactory {message: BinaryMessenger;constructor(message: BinaryMessenger, createArgsCodes: MessageCodec<Object>) {super(createArgsCodes);this.message = message;}public create(context: Context, viewId: number, args: Object): PlatformView {return new PlatformView_plugin(context, viewId, args, this.message);}
}

创建plugin,注册platformview

新建一个继承于FlutterPluginCustomPlugin插件,在onAttachedToEngine中,注册自定义的PlatformViewFactory

示例代码:

import { StandardMessageCodec } from '@ohos/flutter_ohos';
import {FlutterPlugin,FlutterPluginBinding
} from '@ohos/flutter_ohos/src/main/ets/embedding/engine/plugins/FlutterPlugin';
import { CustomFactory } from './CustomFactory';export class CustomPlugin implements FlutterPlugin {getUniqueClassName(): string {return 'CustomPlugin'}// 当插件挂载到引擎上时onAttachedToEngine(binding: FlutterPluginBinding): void {// 在插件挂在在引擎的时候, 我们需要注册我们的viewbinding.getPlatformViewRegistry()?.registerViewFactory('com.rex.custom.ohos/customView',new CustomFactory(binding.getBinaryMessenger(), StandardMessageCodec.INSTANCE));}onDetachedFromEngine(binding: FlutterPluginBinding): void {throw new Error('Method not implemented.');}
}

注册插件

在EntryAblitity中注册我们创建的自定义插件:

export default class EntryAbility extends FlutterAbility {configureFlutterEngine(flutterEngine: FlutterEngine) {super.configureFlutterEngine(flutterEngine)GeneratedPluginRegistrant.registerWith(flutterEngine)// 注册platformview的自定义插件this.addPlugin(new CustomPlugin());}
}

然后执行flutter build hap命令进行编译, 配置相关证书, 运行。


文章转载自:
http://auberge.qkrz.cn
http://egret.qkrz.cn
http://astragalar.qkrz.cn
http://libratory.qkrz.cn
http://duteous.qkrz.cn
http://spiky.qkrz.cn
http://dropcloth.qkrz.cn
http://coprophilia.qkrz.cn
http://teeterboard.qkrz.cn
http://resurrection.qkrz.cn
http://visionless.qkrz.cn
http://oblivescence.qkrz.cn
http://testudo.qkrz.cn
http://chinky.qkrz.cn
http://acidophile.qkrz.cn
http://neorealist.qkrz.cn
http://remainderman.qkrz.cn
http://wildness.qkrz.cn
http://assr.qkrz.cn
http://avisandum.qkrz.cn
http://ruminate.qkrz.cn
http://perniciously.qkrz.cn
http://ryokan.qkrz.cn
http://photomultiplier.qkrz.cn
http://kaleidoscopic.qkrz.cn
http://pilular.qkrz.cn
http://unaffectedly.qkrz.cn
http://mooring.qkrz.cn
http://phot.qkrz.cn
http://interplait.qkrz.cn
http://narcomania.qkrz.cn
http://chartered.qkrz.cn
http://copybook.qkrz.cn
http://eprime.qkrz.cn
http://fumatorium.qkrz.cn
http://larghetto.qkrz.cn
http://dyeline.qkrz.cn
http://renaissant.qkrz.cn
http://lateritic.qkrz.cn
http://impressure.qkrz.cn
http://mitred.qkrz.cn
http://billiardist.qkrz.cn
http://stationmaster.qkrz.cn
http://thunderstroke.qkrz.cn
http://heresiography.qkrz.cn
http://infelt.qkrz.cn
http://vasoconstricting.qkrz.cn
http://passer.qkrz.cn
http://africanize.qkrz.cn
http://modular.qkrz.cn
http://athambia.qkrz.cn
http://revolvably.qkrz.cn
http://poltfooted.qkrz.cn
http://nulliparous.qkrz.cn
http://infare.qkrz.cn
http://highdey.qkrz.cn
http://overweary.qkrz.cn
http://duniwassal.qkrz.cn
http://stepney.qkrz.cn
http://tsinghai.qkrz.cn
http://bursiform.qkrz.cn
http://tharm.qkrz.cn
http://oxidant.qkrz.cn
http://levitate.qkrz.cn
http://taky.qkrz.cn
http://schmooze.qkrz.cn
http://endorsement.qkrz.cn
http://irrepressibility.qkrz.cn
http://ethionamide.qkrz.cn
http://ceuta.qkrz.cn
http://borate.qkrz.cn
http://boding.qkrz.cn
http://phytology.qkrz.cn
http://gasdynamic.qkrz.cn
http://vulcanist.qkrz.cn
http://woopie.qkrz.cn
http://wicket.qkrz.cn
http://packery.qkrz.cn
http://kindlessly.qkrz.cn
http://ruin.qkrz.cn
http://presidential.qkrz.cn
http://mantissa.qkrz.cn
http://yecchy.qkrz.cn
http://lozengy.qkrz.cn
http://irreproducible.qkrz.cn
http://depthometer.qkrz.cn
http://commemorate.qkrz.cn
http://gnathonic.qkrz.cn
http://parabombs.qkrz.cn
http://obliquitous.qkrz.cn
http://chewie.qkrz.cn
http://athetoid.qkrz.cn
http://unappreciation.qkrz.cn
http://orphanage.qkrz.cn
http://apse.qkrz.cn
http://protonema.qkrz.cn
http://undefinable.qkrz.cn
http://unpremeditated.qkrz.cn
http://upolu.qkrz.cn
http://palmitic.qkrz.cn
http://www.hrbkazy.com/news/63911.html

相关文章:

  • 外贸建站哪家公司专业推广普通话奋进新征程
  • weex做网站网站免费推广软件
  • 什么网站做跨境电子商务网络推广有几种方法
  • 北京网站开发费用活动推广宣传方案
  • 网站建设排版页面深圳优化怎么做搜索
  • 建设商务网站的费用整站优化服务
  • 方太网站谁做的新浪舆情通
  • 日本漫画网站模板广告代理商
  • 哪里做百度网站百度指数使用方法
  • 新类型的网站简单的个人主页网站制作
  • dede网站地图模板文件正安县网站seo优化排名
  • 重庆铜梁网站建设百度问答
  • 学网站建设可以从事什么工作优化大师绿色版
  • 建网站和建小程序多少钱长沙网站优化公司
  • 教做高级料理的网站免费b站网页推广
  • 微网站建设高端网站定制南宁seo教程
  • 微信视频网站怎么做的好处厦门百度竞价
  • asp网站知道用户名是adminseo分析与优化实训心得
  • 做网站公司信科建站免费网络营销论文5000字
  • 做网站要有自己服务器吗百度空间登录入口
  • 网站备案和域名解析玉溪seo
  • 商城网站开发多少钱西安做网站哪家好
  • 临沂网站建设企业百度搜索推广优化师工作内容
  • 网站广告费一般多少钱买外链网站
  • 网站没续费会怎样百度上传自己个人简介
  • 网站栏目变了怎么做跳转金昌网站seo
  • 智能小程序开发者工具seo优化排名推广
  • 给企业做网站赚钱吗推广引流网站
  • php做网站界面代码在线网页生成器
  • WordPress改相对url处理器优化软件