49 lines
1.2 KiB
Dart
49 lines
1.2 KiB
Dart
import 'dart:async';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:union_ad_ssgf/flutter_union_ad.dart';
|
|
import 'package:union_ad_ssgf_example/ads_config.dart';
|
|
import 'package:union_ad_ssgf_example/home_page.dart';
|
|
|
|
void main() {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
runApp(const MyApp());
|
|
}
|
|
|
|
class MyApp extends StatefulWidget {
|
|
const MyApp({super.key});
|
|
|
|
@override
|
|
State<MyApp> createState() => _MyAppState();
|
|
}
|
|
|
|
class _MyAppState extends State<MyApp> {
|
|
bool initAd = false;
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
init();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
home: HomePage(initAD: initAd),
|
|
);
|
|
}
|
|
|
|
/// 初始化广告 SDK
|
|
Future<void> init() async {
|
|
bool result = await FlutterUnionAd.register(
|
|
androidId: AdsConfig.androidAppId,
|
|
iosId: AdsConfig.iosAppId,
|
|
debug: true, // 是否显示日志log
|
|
personalized: FlutterTencentadPersonalized.close, // 是否显示个性化推荐广告
|
|
channelId: FlutterTencentadChannel.tencent, //渠道id
|
|
);
|
|
debugPrint("广告SDK 初始化${result ? '成功' : '失败'}");
|
|
setState(() {
|
|
initAd = result;
|
|
});
|
|
}
|
|
}
|