custom_character_add_view.dart 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. import 'package:cached_network_image/cached_network_image.dart';
  2. import 'package:easy_refresh/easy_refresh.dart';
  3. import 'package:flutter_screenutil/flutter_screenutil.dart';
  4. import 'package:flutter_slidable/flutter_slidable.dart';
  5. import 'package:keyboard/base/base_view.dart';
  6. import 'package:keyboard/dialog/custom_character/custom_character_add_controller.dart';
  7. import 'package:flutter/material.dart';
  8. import 'package:get/get.dart';
  9. import '../../data/bean/character_info.dart';
  10. import '../../data/bean/keyboard_info.dart';
  11. import '../../data/repository/characters_repository.dart';
  12. import '../../data/repository/keyboard_repository.dart';
  13. import '../../di/get_it.dart';
  14. import '../../resource/assets.gen.dart';
  15. import '../../resource/string.gen.dart';
  16. import '../../utils/styles.dart';
  17. class CustomCharacterAddView extends BaseView<CustomCharacterAddController> {
  18. final KeyboardInfo currentKeyboardInfo;
  19. @override
  20. String? get tag => "CustomCharacterAddController${currentKeyboardInfo.id}";
  21. const CustomCharacterAddView({super.key, required this.currentKeyboardInfo});
  22. @override
  23. backgroundColor() => const Color(0xFFF6F5FA);
  24. @override
  25. Widget buildBody(BuildContext context) {
  26. Get.delete<CustomCharacterAddController>(tag: tag);
  27. Get.put(
  28. CustomCharacterAddController(
  29. getIt.get<CharactersRepository>(),
  30. getIt.get<KeyboardRepository>(),
  31. currentKeyboardInfo: currentKeyboardInfo,
  32. ),
  33. tag: tag,
  34. );
  35. return Obx(() {
  36. if (controller.characterList.isEmpty) {
  37. return _buildCustomListEmpty();
  38. }
  39. return EasyRefresh(
  40. controller: controller.refreshController,
  41. header: const ClassicHeader(),
  42. footer: ClassicFooter(
  43. showMessage: false,
  44. noMoreText: StringName.noMoreData,
  45. failedText: StringName.loadFailed,
  46. processedText: StringName.loadCompleted,
  47. processingText: StringName.loading,
  48. ),
  49. // onRefresh: controller.refreshData,
  50. onLoad: controller.loadMoreData,
  51. child: ListView.separated(
  52. padding: EdgeInsets.zero,
  53. itemCount: controller.characterList.length,
  54. itemBuilder: (context, index) {
  55. return _buildListItem(
  56. characterInfo: controller.characterList[index],
  57. );
  58. },
  59. separatorBuilder: (BuildContext context, int index) {
  60. return SizedBox(
  61. width: double.infinity,
  62. height: 10.h,
  63. child: Container(color: const Color(0xFFF4F2FB)),
  64. );
  65. },
  66. ),
  67. );
  68. });
  69. }
  70. Widget _buildListItem({required CharacterInfo characterInfo}) {
  71. return GestureDetector(
  72. onTap: () {
  73. controller.itemButtonClick(characterInfo);
  74. },
  75. child: Container(
  76. decoration: ShapeDecoration(
  77. color: Colors.white,
  78. shape: RoundedRectangleBorder(
  79. borderRadius: BorderRadius.circular(12.r),
  80. ),
  81. ),
  82. height: 88.h,
  83. padding: EdgeInsets.symmetric(horizontal: 16.w),
  84. child: Row(
  85. children: [
  86. _buildAvatar(imageUrl: characterInfo.imageUrl),
  87. SizedBox(width: 8.w),
  88. _buildCharacterInfo(characterInfo),
  89. _buildActionButton(characterInfo),
  90. ],
  91. ),
  92. ),
  93. );
  94. }
  95. /// 角色头像
  96. Widget _buildAvatar({required String? imageUrl}) {
  97. return Container(
  98. width: 60.r,
  99. height: 60.r,
  100. decoration: BoxDecoration(
  101. borderRadius: BorderRadius.circular(8),
  102. gradient: LinearGradient(
  103. begin: Alignment.topCenter,
  104. end: Alignment.bottomCenter,
  105. colors: [Color(0xffebe6ff), Color(0xffffe6fe)],
  106. ),
  107. ),
  108. child: ClipRRect(
  109. borderRadius: BorderRadius.circular(8.r),
  110. child: CachedNetworkImage(
  111. imageUrl: imageUrl ?? "",
  112. width: 60.r,
  113. height: 60.r,
  114. fit: BoxFit.contain,
  115. errorWidget:
  116. (_, __, ___) => Assets.images.iconSystemKeyboard.image(
  117. width: 60.r,
  118. height: 60.r,
  119. fit: BoxFit.contain,
  120. ),
  121. ),
  122. ),
  123. );
  124. }
  125. /// 构建角色信息,包括名称、VIP标识和描述
  126. Widget _buildCharacterInfo(CharacterInfo characterInfo) {
  127. return Expanded(
  128. child: Column(
  129. mainAxisAlignment: MainAxisAlignment.center,
  130. crossAxisAlignment: CrossAxisAlignment.start,
  131. children: [
  132. Row(
  133. children: [
  134. Text(
  135. characterInfo.name ?? "",
  136. style: TextStyle(
  137. color: Colors.black.withAlpha(204),
  138. fontSize: 15.sp,
  139. fontWeight: FontWeight.w500,
  140. ),
  141. ),
  142. SizedBox(width: 4.w),
  143. characterInfo.isVip == true
  144. ? Assets.images.iconCharacterVip.image(
  145. width: 38.w,
  146. height: 16.h,
  147. )
  148. : Container(),
  149. ],
  150. ),
  151. Text(
  152. characterInfo.description ?? "",
  153. softWrap: true,
  154. style: TextStyle(
  155. color: Colors.black.withAlpha(153),
  156. fontSize: 12.sp,
  157. fontWeight: FontWeight.w400,
  158. ),
  159. ),
  160. ],
  161. ),
  162. );
  163. }
  164. /// 按钮
  165. Widget _buildActionButton(CharacterInfo characterInfo) {
  166. return InkWell(
  167. onTap: () {
  168. controller.itemButtonClick(characterInfo);
  169. },
  170. child: Container(
  171. width: 72.w,
  172. height: 28.h,
  173. margin: EdgeInsets.only(left: 8.w),
  174. decoration: BoxDecoration(
  175. borderRadius: BorderRadius.circular(50.r),
  176. gradient:
  177. characterInfo.isAdd == true
  178. ? null
  179. : const LinearGradient(
  180. colors: [Color(0xFF7D46FC), Color(0xFFBC87FF)],
  181. begin: Alignment.topLeft,
  182. end: Alignment.bottomRight,
  183. ),
  184. color: characterInfo.isAdd == true ? const Color(0xFFEDE8FF) : null,
  185. ),
  186. child: Row(
  187. mainAxisAlignment: MainAxisAlignment.center,
  188. children: [
  189. if (characterInfo.isLock == true && characterInfo.isVip == true)
  190. Padding(
  191. padding: EdgeInsets.only(right: 2.w),
  192. child: Assets.images.iconCharacterLock.image(
  193. width: 18.r,
  194. height: 18.r,
  195. ), // 锁定图标
  196. ),
  197. Text(
  198. characterInfo.isLock == true && characterInfo.isVip == true
  199. ? StringName.characterUnlock
  200. : characterInfo.isAdd == true
  201. ? StringName.characterAdded
  202. : StringName.characterAdd,
  203. style: TextStyle(
  204. color:
  205. characterInfo.isAdd == true
  206. ? const Color(0xFF7D46FC)
  207. : Colors.white,
  208. fontSize: 14.sp,
  209. fontWeight: FontWeight.w500,
  210. ),
  211. ),
  212. ],
  213. ),
  214. ),
  215. );
  216. }
  217. Widget _buildCustomListEmpty() {
  218. return Container(
  219. alignment: Alignment.center,
  220. child: Column(
  221. children: [
  222. SizedBox(height: 100.w),
  223. Assets.images.iconCharacterCustomListEmpty.image(
  224. width: 161.w,
  225. height: 139.w,
  226. ),
  227. Text(
  228. StringName.characterCustomListEmpty,
  229. style: TextStyle(
  230. color: Colors.black.withAlpha(178),
  231. fontSize: 14.sp,
  232. fontWeight: FontWeight.w400,
  233. ),
  234. ),
  235. ],
  236. ));
  237. }
  238. }