git-subtree-dir: app git-subtree-mainline:6ebd902c6bgit-subtree-split:a11a668869
53 lines
1.7 KiB
Dart
53 lines
1.7 KiB
Dart
import 'package:flutter/material.dart';
|
||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||
|
||
import '../config/app_config.dart';
|
||
|
||
/// 广告服务抽象:P0 用 Mock(保证业务链路可开发可测),P1 换穿山甲 SDK
|
||
abstract class AdsService {
|
||
/// 广告是否开通(AppConfig.pangleAppId 非空);未开通时广告位与激励均不渲染
|
||
bool get enabled;
|
||
Future<bool> showRewarded();
|
||
|
||
/// 横幅/信息流广告位(Mock 返回占位卡,P1 换原生广告组件)
|
||
Widget showBanner(BuildContext context);
|
||
}
|
||
|
||
/// 本地模拟广告(约 1 秒"播放"后返回完整观看)
|
||
class MockAdsService implements AdsService {
|
||
@override
|
||
bool get enabled => AppConfig.pangleAppId.isNotEmpty;
|
||
|
||
@override
|
||
Future<bool> showRewarded() async {
|
||
await Future.delayed(const Duration(milliseconds: 900));
|
||
return true;
|
||
}
|
||
|
||
@override
|
||
Widget showBanner(BuildContext context) {
|
||
final scheme = Theme.of(context).colorScheme;
|
||
return Container(
|
||
height: 90,
|
||
margin: const EdgeInsets.fromLTRB(12, 0, 12, 12),
|
||
decoration: BoxDecoration(
|
||
color: scheme.primaryContainer.withValues(alpha: 0.5),
|
||
borderRadius: BorderRadius.circular(12),
|
||
),
|
||
child: const Row(
|
||
mainAxisAlignment: MainAxisAlignment.center,
|
||
children: [
|
||
Icon(Icons.campaign_outlined, size: 20),
|
||
SizedBox(width: 8),
|
||
Text('广告位(P1 接入穿山甲)', style: TextStyle(fontSize: 12)),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
}
|
||
|
||
final adsServiceProvider = Provider<AdsService>((ref) {
|
||
// P1:AppConfig.pangleAppId 非空时替换为 PangleAdsService(穿山甲 SDK 实现)
|
||
return MockAdsService();
|
||
});
|