From da620c6334f99535e0748555ae75feed368cf8b4 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期五, 06 五月 2022 18:56:22 +0800 Subject: [PATCH] 功能完善 --- flutter_module/lib/ui/widget/ad_express.dart | 66 +++++++++++++++++++++++++++++++++ 1 files changed, 66 insertions(+), 0 deletions(-) diff --git a/flutter_module/lib/ui/widget/ad_express.dart b/flutter_module/lib/ui/widget/ad_express.dart index a55d624..ca98fcf 100644 --- a/flutter_module/lib/ui/widget/ad_express.dart +++ b/flutter_module/lib/ui/widget/ad_express.dart @@ -147,3 +147,69 @@ }); } } + +class DrawVideoWidget extends StatefulWidget { + final String pid; + final ExpressAdController? controller; + final VoidCallback? close; + final VoidCallback? loadFail; + + DrawVideoWidget(this.pid, {this.controller, this.close, this.loadFail}); + + @override + State<StatefulWidget> createState() => _DrawVideoState(); +} + +class _DrawVideoState extends State<DrawVideoWidget> { + MethodChannel? _expressAdChannel; + + @override + void initState() { + super.initState(); + if (widget.controller != null) { + widget.controller!.refresh = () { + if (_expressAdChannel != null) { + _expressAdChannel!.invokeMethod("refresh"); + } + }; + } + } + + @override + Widget build(BuildContext context) { + return KeepAliveWrapper( + child: Platform.isAndroid + ? AndroidView( + viewType: "ad-draw-video-view", + layoutDirection: TextDirection.ltr, + onPlatformViewCreated: onPlatformViewCreated, + creationParams: <String, dynamic>{ + "pid": widget.pid + }, + creationParamsCodec: const StandardMessageCodec(), + ) + : UiKitView( + viewType: "ad-draw-video-view", + layoutDirection: TextDirection.ltr, + onPlatformViewCreated: onPlatformViewCreated, + creationParams: <String, dynamic>{"pid": widget.pid}, + creationParamsCodec: const StandardMessageCodec(), + )); + } + + Future<void> onPlatformViewCreated(id) async { + _expressAdChannel = MethodChannel("ad-draw-video-view-$id"); + _expressAdChannel!.setMethodCallHandler((call) { + if ("close" == call.method) { + if (widget.close != null) { + widget.close!(); + } + } else if ("loadFail" == call.method) { + if (widget.loadFail != null) { + widget.loadFail!(); + } + } + return Future.value(""); + }); + } +} -- Gitblit v1.8.0