bwt_ad_flutter 0.1.3 copy "bwt_ad_flutter: ^0.1.3" to clipboard
bwt_ad_flutter: ^0.1.3 copied to clipboard

BWT广告SDK的Flutter插件,该插件可以帮助您更加简单、便捷、快速的集成BWT的安卓、iOS原生广告SDK。

example/lib/main.dart

import 'dart:io';

import 'package:bwt_ad_flutter/et/BwtAdLogType.dart';
import 'package:bwt_ad_flutter_example/page/InterstitialAdPage.dart';
import 'package:bwt_ad_flutter_example/page/NativeExpressAdListDataPage.dart';
import 'package:bwt_ad_flutter_example/page/NativeExpressAdPage.dart';
import 'package:bwt_ad_flutter_example/page/SplashAdPage.dart';
import 'package:bwt_ad_flutter_example/util/DisplayUtil.dart';
import 'package:bwt_ad_flutter_example/widget/SimpleWidget.dart';
import 'package:flutter/material.dart';
import 'package:bwt_ad_flutter/BwtAdCore.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  /// 初始化广告插件
  await BwtAdCore.init(
    appId: Platform.isAndroid ? '400805' : '310641',
    // iOS请求广告前是否先申请IDFA,默认true
    isRequestIdfa: true,
    // 广告内部日志打印设置,默认为NONE(不打印),正式包建议设置为NONE
    logType: BwtAdLogType.DEBUG,
  );

  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  static const _adTypeList = [
    {
      'type': 0,
      'title': '开屏广告',
    },
    {
      'type': 1,
      'title': '插屏广告',
    },
    {
      'type': 2,
      'title': '信息流模板广告',
    },
    {
      'type': 3,
      'title': '信息流模板广告-列表场景',
    }
  ];

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    DisplayUtil.init(context);

    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('BwtAdSdkFlutter'),
        ),
        body: ListView.builder(
            padding: const EdgeInsets.symmetric(vertical: 32, horizontal: 16),
            itemCount: _adTypeList.length,
            itemBuilder: (context, index) {
              Map<String, dynamic> adType = _adTypeList[index];
              return SimpleWidget(
                width: double.infinity,
                height: 64,
                alignment: Alignment.center,
                onTap: () {
                  _onItemClick(adType['type'], context);
                },
                child: Text(
                  adType['title'] ?? '',
                  style: const TextStyle(
                      color: Colors.black,
                      fontSize: 20,
                      fontWeight: FontWeight.bold),
                ),
              );
            }),
      ),
    );
  }

  /// List item 点击
  void _onItemClick(adType, BuildContext context) {
    if (0 == adType) {
      _push(context, const SplashAdPage());
    } else if (1 == adType) {
      _push(context, const InterstitialAdPage());
    } else if (2 == adType) {
      _push(context, const NativeExpressAdPage());
    } else if (3 == adType) {
      _push(context, const NativeExpressAdListDataPage());
    }
  }

  /// 跳转到指定页面
  void _push(BuildContext context, Widget widget) {
    Navigator.push(context, MaterialPageRoute(builder: (context) {
      return widget;
    }));
  }
}
1
likes
0
points
126
downloads

Publisher

unverified uploader

Weekly Downloads

BWT广告SDK的Flutter插件,该插件可以帮助您更加简单、便捷、快速的集成BWT的安卓、iOS原生广告SDK。

Homepage

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on bwt_ad_flutter

Packages that implement bwt_ad_flutter