增加广告组件,个人中心

This commit is contained in:
唐明明
2022-05-27 17:52:17 +08:00
parent 4a635f3570
commit d64bf95b25
269 changed files with 3960 additions and 309 deletions

View File

@@ -0,0 +1,92 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'ad.dart';
/// Widget for banner ad
class NativeExpressAdView extends StatelessWidget {
final String adId;
final double width;
final double height;
final AdCallback onSjmAdLoaded;
final AdCallback onSjmAdShow;
final AdCallback onSjmAdClicked;
final AdCallback onSjmAdClosed;
final AdErrorCallback onSjmAdError;
NativeExpressAdView(
{Key key,
this.adId,
this.width,
this.height,
this.onSjmAdLoaded,
this.onSjmAdShow,
this.onSjmAdClicked,
this.onSjmAdClosed,
this.onSjmAdError})
: super(key: key);
@override
Widget build(BuildContext context) {
Widget banner;
if (defaultTargetPlatform == TargetPlatform.android) {
banner = AndroidView(
viewType: 'flutter_adsjm_plugin/native_express',
creationParams: {
"adId": adId,
"width": width,
"height": height,
},
creationParamsCodec: const StandardMessageCodec(),
onPlatformViewCreated: _onPlatformViewCreated,
);
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
banner = UiKitView(
viewType: 'flutter_adsjm_plugin/native_express',
creationParams: {
"adId": adId,
"width": width,
"height": height,
},
creationParamsCodec: const StandardMessageCodec(),
onPlatformViewCreated: _onPlatformViewCreated,
);
} else {
banner = Text("Not supported");
}
return Container(
width: width,
height: height,
child: banner,
);
}
void _onPlatformViewCreated(int id) {
EventChannel eventChannel = EventChannel("flutter_adsjm_plugin/native_express_event_$id");
eventChannel.receiveBroadcastStream().listen((event) {
switch (event["event"]) {
case "onSjmAdLoaded":
onSjmAdLoaded?.call(event["id"]);
break;
case "onSjmAdShow":
onSjmAdShow?.call(event["id"]);
break;
case "onSjmAdClicked":
onSjmAdClicked?.call(event["id"]);
break;
case "onSjmAdClosed":
onSjmAdClosed?.call(event["id"]);
break;
case "onSjmAdError":
onSjmAdError?.call(event["id"], event["code"], event["message"]);
break;
}
});
}
}