154 lines
4.5 KiB
Dart
154 lines
4.5 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/images/heart.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,
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|