배너를 추가하고자 하는 위치에 아래의 위젯을 생성하여 등록합니다.
AndroidView 내 아래 설정을 반드시 추가합니다.
Widget _setBannerView() {
const String viewType = 'AdPopcornSSPBannerView';
if (Platform.isAndroid) {
final Map<String, dynamic> creationParams = <String, dynamic>
{'appKey':'your_app_key', 'placementId':'your_placement_id', 'bannerSize':'320x50'};
return Container(
width: double.maxFinite,
height:50,
child: AndroidView(
viewType: viewType,
layoutDirection: TextDirection.ltr,
creationParams: creationParams,
creationParamsCodec: const StandardMessageCodec(),
),
);
}
else if (Platform.isIOS) {
final Map<String, dynamic> creationParams = <String, dynamic>
{'appKey':'your_app_key', 'placementId':'your_placement_id', 'bannerSize':'320x50'};
return Container(
width: double.maxFinite,
height:50,
child: UiKitView(
viewType: viewType,
layoutDirection: TextDirection.ltr,
creationParams: creationParams,
creationParamsCodec: const StandardMessageCodec(),
),
);
}
else{
return Container(
width: double.maxFinite,
height: 1
);
}
}
배너의 이벤트를 전달 받고 싶은 경우, 아래의 규칙으로 method channel을 생성합니다.
class _MyAppState extends State<MyApp> {
static const MethodChannel androidBannerChannel = const MethodChannel('adpopcornssp/your_placement_id');
static const MethodChannel iosBannerChannel = const MethodChannel('adpopcornssp/your_placement_id');
@override
void initState() {
super.initState();
if (Platform.isAndroid) {
AdPopcornSSP.init('663451319');
// 배너 이벤트 채널 연동
androidBannerChannel.setMethodCallHandler(_eventHandleMethod);
} else if (Platform.isIOS) {
AdPopcornSSP.init('397261446');
// 배너 이벤트 채널 연동
iosBannerChannel.setMethodCallHandler(_eventHandleMethod);
}
}
static Future<dynamic> _eventHandleMethod(MethodCall call) {
final Map<dynamic, dynamic> arguments = call.arguments;
final String method = call.method;
final String placementId = arguments['placementId'];
if (method == 'APSSPBannerViewLoadSuccess') {
} else if (method == 'APSSPBannerViewLoadFail') {
final int errorCode = arguments['errorCode'];
} else if (method == 'APSSPBannerViewClicked'){
}
return Future<dynamic>.value(null);
}
}