初始化
This commit is contained in:
@@ -0,0 +1,188 @@
|
||||
//广告item
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:hgdj/assets_tool/images.dart';
|
||||
import 'package:hgdj/hj_utils/api_service/common_service.dart';
|
||||
import 'package:hgdj/hj_utils/screen.dart';
|
||||
|
||||
import '../../hj_model/splash/ads_model.dart';
|
||||
import '../../routers/jump_router.dart';
|
||||
import '../widget/net_image_widget.dart';
|
||||
|
||||
enum AdShowType {
|
||||
img, // 纯图片
|
||||
hor, // 水平:左图标题 + 右下载按钮
|
||||
vImgText, // 图文:上图下文
|
||||
splash, // 启动全屏图
|
||||
}
|
||||
|
||||
//所有广告判断
|
||||
class AdsItem extends StatefulWidget {
|
||||
final AdsInfoModel adInfo;
|
||||
final double? aspectRatio;
|
||||
final AdShowType? showType;
|
||||
final double borderRadius;
|
||||
final int clickType; //0:应用 1:广告
|
||||
final Widget? child; //自定义子视图(IM 广告用)
|
||||
final VoidCallback? onTap; //点击附加回调(IM 广告已读上报用)
|
||||
|
||||
const AdsItem({
|
||||
super.key,
|
||||
required this.adInfo,
|
||||
this.aspectRatio,
|
||||
this.showType,
|
||||
this.borderRadius = 12,
|
||||
this.clickType = 1,
|
||||
this.child,
|
||||
this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
State<AdsItem> createState() => _AdsItemState();
|
||||
}
|
||||
|
||||
class _AdsItemState extends State<AdsItem> {
|
||||
AdsInfoModel get adInfo => widget.adInfo;
|
||||
|
||||
void _onTap() {
|
||||
pushToPageByLink(adInfo.href);
|
||||
CommonService.adsClick(widget.clickType);
|
||||
widget.onTap?.call();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return InkWell(
|
||||
enableFeedback: false,
|
||||
onTap: _onTap,
|
||||
child: widget.child ??
|
||||
switch (widget.showType) {
|
||||
AdShowType.img => _buildImageStyle(),
|
||||
AdShowType.hor => _buildHorStyle(),
|
||||
AdShowType.vImgText => _buildImageTextStyle(),
|
||||
AdShowType.splash => _buildSplash(),
|
||||
_ => _buildNormalStyle(),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// 启动全屏图:封面铺满 + 兜底背景图
|
||||
Widget _buildSplash() {
|
||||
return NetworkImageLoader(
|
||||
imageUrl: adInfo.cover ?? '',
|
||||
width: Get.width,
|
||||
height: Get.height,
|
||||
fit: BoxFit.cover,
|
||||
placeHolderWidget: Image.asset(
|
||||
'ic_splash_bg.webp'.launchPath,
|
||||
fit: BoxFit.cover,
|
||||
width: Get.width,
|
||||
height: Get.height,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 默认样式:上图下标题(九宫格项)
|
||||
Widget _buildNormalStyle() {
|
||||
return Column(
|
||||
children: [
|
||||
AspectRatio(
|
||||
aspectRatio: widget.aspectRatio ?? 1,
|
||||
child: NetworkImageLoader(
|
||||
imageUrl: adInfo.cover ?? '', borderRadius: 12),
|
||||
),
|
||||
const Spacer(),
|
||||
Text(
|
||||
adInfo.title?.trim() ?? '',
|
||||
maxLines: 1,
|
||||
style: const TextStyle(color: Color(0xffFAFAFA), fontSize: 11),
|
||||
),
|
||||
const Spacer(),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// 图文样式:上图下文
|
||||
Widget _buildImageTextStyle() {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
AspectRatio(
|
||||
aspectRatio: 72 / 20,
|
||||
child: NetworkImageLoader(
|
||||
borderRadius: 4,
|
||||
imageUrl: adInfo.cover ?? '',
|
||||
width: double.infinity,
|
||||
height: double.infinity,
|
||||
fit: BoxFit.fill,
|
||||
),
|
||||
),
|
||||
10.sizeBoxH,
|
||||
Text(
|
||||
adInfo.title ?? '',
|
||||
style: const TextStyle(
|
||||
color: Color(0xffdddfdf),
|
||||
fontWeight: FontWeight.w300,
|
||||
fontSize: 12.0,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// 纯图样式:可选宽高比
|
||||
Widget _buildImageStyle() {
|
||||
final image = NetworkImageLoader(
|
||||
imageUrl: adInfo.cover ?? '',
|
||||
borderRadius: widget.borderRadius,
|
||||
fit: BoxFit.fill,
|
||||
);
|
||||
if (widget.aspectRatio == null) return image;
|
||||
return AspectRatio(aspectRatio: widget.aspectRatio!, child: image);
|
||||
}
|
||||
|
||||
// 水平样式:左图+标题,右「立即下载」按钮
|
||||
Widget _buildHorStyle() {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
child: NetworkImageLoader(
|
||||
imageUrl: adInfo.cover ?? '',
|
||||
borderRadius: 10,
|
||||
width: 50,
|
||||
height: 50,
|
||||
),
|
||||
),
|
||||
10.sizeBoxW,
|
||||
Text(
|
||||
adInfo.title ?? '',
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w300,
|
||||
fontSize: 12.0,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Container(
|
||||
width: 72,
|
||||
height: 28,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xff3476FF),
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
),
|
||||
child: const Center(
|
||||
child: Text(
|
||||
'立即下载',
|
||||
style: TextStyle(color: Colors.white, fontSize: 12),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user