character_tab_group_content_view.dart 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. import 'package:cached_network_image/cached_network_image.dart';
  2. import 'package:easy_refresh/easy_refresh.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_screenutil/flutter_screenutil.dart';
  5. import 'package:get/get.dart';
  6. import 'package:get_it/get_it.dart';
  7. import 'package:keyboard/base/base_view.dart';
  8. import 'package:keyboard/resource/string.gen.dart';
  9. import '../../../data/bean/character_info.dart';
  10. import '../../../resource/assets.gen.dart';
  11. import '../../data/bean/character_group_info.dart';
  12. import '../../data/bean/keyboard_info.dart';
  13. import '../../data/repository/characters_repository.dart';
  14. import 'character_tab_group_content_controller.dart';
  15. class CharacterTabGroupContentView
  16. extends BaseView<CharacterTabGroupContentController> {
  17. final CharacterGroupInfo characterGroupInfo;
  18. final KeyboardInfo currentKeyboardInfo;
  19. const CharacterTabGroupContentView({
  20. super.key,
  21. required this.characterGroupInfo,
  22. required this.currentKeyboardInfo,
  23. });
  24. @override
  25. String? get tag =>
  26. "CharacterTabGroupContentController KeyId${currentKeyboardInfo.id}GroupId${characterGroupInfo.id}";
  27. @override
  28. backgroundColor() => const Color(0xFFF4F2FB);
  29. @override
  30. Widget buildBody(BuildContext context) {
  31. Get.delete<CharacterTabGroupContentController>(
  32. tag: tag,
  33. ); // **删除旧 Controller**
  34. Get.lazyPut(
  35. () => CharacterTabGroupContentController(
  36. GetIt.instance.get<CharactersRepository>(),
  37. currentCharacterGroupInfo: characterGroupInfo,
  38. currentKeyboardInfo: currentKeyboardInfo,
  39. ),
  40. tag: tag,
  41. );
  42. return Column(
  43. children: [
  44. Expanded(
  45. child: Obx(() {
  46. return EasyRefresh(
  47. controller: controller.refreshController,
  48. header: const ClassicHeader(),
  49. footer: ClassicFooter(
  50. showMessage: false,
  51. noMoreText: StringName.noMoreData,
  52. failedText: StringName.loadFailed,
  53. processedText: StringName.loadCompleted,
  54. processingText: StringName.loading,
  55. ),
  56. // onRefresh: controller.refreshData,
  57. onLoad: controller.loadMoreData,
  58. child: ListView.separated(
  59. padding: EdgeInsets.zero,
  60. itemCount: controller.characterList.length,
  61. itemBuilder: (context, index) {
  62. return _buildListItem(
  63. characterInfo: controller.characterList[index],
  64. );
  65. },
  66. separatorBuilder: (BuildContext context, int index) {
  67. return SizedBox(
  68. width: double.infinity,
  69. height: 10.h,
  70. child: Container(color: const Color(0xFFF4F2FB)),
  71. );
  72. },
  73. ),
  74. );
  75. }),
  76. ),
  77. ],
  78. );
  79. }
  80. Widget _buildListItem({required CharacterInfo characterInfo}) {
  81. return GestureDetector(
  82. onTap: () {
  83. controller.itemButtonClick(characterInfo);
  84. },
  85. child: Container(
  86. padding: EdgeInsets.all(14.r),
  87. decoration: ShapeDecoration(
  88. color: Colors.white,
  89. shape: RoundedRectangleBorder(
  90. borderRadius: BorderRadius.circular(12.r),
  91. ),
  92. ),
  93. child: Row(
  94. children: [
  95. _buildAvatar(imageUrl: characterInfo.imageUrl),
  96. SizedBox(width: 8.w),
  97. _buildCharacterInfo(characterInfo),
  98. _buildActionButton(characterInfo),
  99. ],
  100. ),
  101. ),
  102. );
  103. }
  104. /// 角色头像
  105. Widget _buildAvatar({required String? imageUrl}) {
  106. return Container(
  107. width: 60.r,
  108. height: 60.r,
  109. decoration: BoxDecoration(
  110. borderRadius: BorderRadius.circular(8),
  111. gradient: LinearGradient(
  112. begin: Alignment.topCenter,
  113. end: Alignment.bottomCenter,
  114. colors: [Color(0xffebe6ff), Color(0xffffe6fe)],
  115. ),
  116. ),
  117. child: CachedNetworkImage(
  118. imageUrl: imageUrl ?? "",
  119. width: 60.r,
  120. height: 60.r,
  121. fit: BoxFit.cover,
  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. }