skywood/lib/utils/tools/help_img.dart
2026-06-28 17:16:31 +08:00

180 lines
5.7 KiB
Dart

import 'package:flutter/material.dart';
// import 'package:lottie/lottie.dart';
// import 'package:flutter_svg/flutter_svg.dart';
class ConstImg {
ConstImg._();
static const String bottomBar = "assets/common/bottom_bar.png";
static const String tabHomeSelected = "assets/common/tab_home_selected.png";
static const String tabHomeUnselect = "assets/common/tab_home_unselect.png";
static const String tabSearchSelected =
"assets/common/tab_search_selected.png";
static const String tabSearchUnselect =
"assets/common/tab_search_unselect.png";
static const String tabLikeSelected = "assets/common/tab_like_selected.png";
static const String tabLikeUnselect = "assets/common/tab_like_unselect.png";
static const String tabMineSelected = "assets/common/tab_mine_selected.png";
static const String tabMineUnselect = "assets/common/tab_mine_unselect.png";
static const String homeBg = "assets/imgs/home_bg.png";
// home_card_bg
static const String homeCardBg = "assets/imgs/home_card_bg.png";
// home_top_bg
static const String homeTopBg = "assets/imgs/home_top_bg.png";
// home_title_daily/hot/hot_cate/mystery/weekly
static const String homeTitleDaily = "assets/imgs/home_title_daily.png";
static const String homeTitleHot = "assets/imgs/home_title_hot.png";
static const String homeTitleHotCate = "assets/imgs/home_title_hot_cate.png";
static const String homeTitleMystery = "assets/imgs/home_title_mystery.png";
static const String homeTitleWeekly = "assets/imgs/home_title_weekly.png";
static const String homeOpenNowBox = "assets/imgs/home_opennow_box.png";
// splash_page
static const String splashPage = "assets/imgs/splash_page.png";
// heart
static const String heart = "assets/imgs/heart.png";
// hot_bg1
static const String hotBg1 = "assets/imgs/hot_bg1.png";
static const String hotBg2 = "assets/imgs/hot_bg2.png";
// home_rank_bg
static const String homeRankBg = "assets/imgs/home_rank_bg.png";
// yellow_bg purple red
static const String yellowBg = "assets/imgs/yellow_bg.png";
static const String purpleBg = "assets/imgs/purple_bg.png";
static const String redBg = "assets/imgs/red_bg.png";
/// pics
static const String delete = "assets/pics/delete.png";
static const String back = "assets/pics/back.png";
static const String search = "assets/pics/search_icon.png";
static const String hot = "assets/pics/hot.png";
static const String star = "assets/pics/star.png";
static const String look = "assets/pics/look.png";
// bgs
static const String likeBg = "assets/pics/like_bg.png";
static const String collectionBg = "assets/pics/collection_bg.png";
static const String playlogBg = "assets/pics/playlog_bg.png";
// like_selected_bg
static const String likeSelectedBg = "assets/pics/like_selected_bg.png";
static const String likeUnselectBg = "assets/pics/like_unselect_bg.png";
static const String continueWatch = "assets/pics/continue_watch.png";
// nodata
static const String noData = "assets/images/nodata.png";
static const String loadingJson = "assets/bagua.json";
// static get appLoading => Lottie.asset(loadingJson, width: 60, height: 60);
}
class HelpImg {
/// load local
static Widget asset(
String path, {
BoxFit? fit,
double? width,
double? height,
Color? color,
bool isDartData = false,
String? dartPath,
}) {
String assets = path;
return Image.asset(
assets,
fit: fit,
width: width,
height: height,
color: color,
);
}
static Widget networkRadius(
String path, {
BoxFit? fit,
double? width,
double? height,
BoxShape? shape,
BorderRadius? borderRadius,
Widget? errorWidget,
}) {
return ClipRRect(
borderRadius: borderRadius ?? BorderRadius.circular(3),
child: network(
path,
fit: fit,
width: width,
height: height,
shape: shape,
errorWidget: errorWidget,
),
);
}
/// load network
static Widget network(
String path, {
BoxFit? fit,
double? width,
double? height,
Color? color,
BoxShape? shape,
BorderRadius? borderRadius,
Widget? errorWidget,
}) {
// bool isSvg = path.toLowerCase().endsWith('.svg');
// if (isSvg) {
// return SvgPicture.network(
// path,
// width: width,
// height: height,
// // fit: fit ?? BoxFit.fill,
// colorFilter: color != null
// ? ColorFilter.mode(color, BlendMode.srcIn)
// : null,
// placeholderBuilder: (context) => Container(
// width: width,
// height: height,
// color: Colors.grey[200],
// child: Center(child: CircularProgressIndicator()),
// ),
// );
// }
return Image.network(
path,
width: width,
height: height,
fit: fit,
loadingBuilder: (context, child, loadingProgress) {
if (loadingProgress == null) return child;
return Center(
//CircularProgressIndicator
child: Container(
width: 50,
height: 50,
padding: const EdgeInsets.all(5),
child: CircularProgressIndicator(
color: Colors.white,
strokeWidth: 2,
),
),
);
},
errorBuilder: (context, error, stackTrace) {
// ✅ 关键:处理加载失败的情况
return errorWidget ??
Container(
width: 50,
height: 50,
color: Colors.grey[300],
child: const Icon(
Icons.broken_image,
color: Colors.grey,
size: 40,
),
);
},
);
}
}