character_tab_group_content_view.dart 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. itemCount: controller.characterList.length,
  60. itemBuilder: (context, index) {
  61. return _buildListItem(
  62. characterInfo: controller.characterList[index],
  63. );
  64. },
  65. separatorBuilder: (BuildContext context, int index) {
  66. return SizedBox(
  67. width: double.infinity,
  68. height: 10.h,
  69. child: Container(color: const Color(0xFFF4F2FB)),
  70. );
  71. },
  72. ),
  73. );
  74. }),
  75. ),
  76. ],
  77. );
  78. }
  79. Widget _buildListItem({required CharacterInfo characterInfo}) {
  80. return GestureDetector(
  81. onTap: () {
  82. controller.itemButtonClick(characterInfo);
  83. },
  84. child: Container(
  85. padding: EdgeInsets.all(14.r),
  86. decoration: ShapeDecoration(
  87. color: Colors.white,
  88. shape: RoundedRectangleBorder(
  89. borderRadius: BorderRadius.circular(12.r),
  90. ),
  91. ),
  92. child: Row(
  93. children: [
  94. _buildAvatar(imageUrl: characterInfo.imageUrl),
  95. SizedBox(width: 8.w),
  96. _buildCharacterInfo(characterInfo),
  97. _buildActionButton(characterInfo),
  98. ],
  99. ),
  100. ),
  101. );
  102. }
  103. /// 角色头像
  104. Widget _buildAvatar({required String? imageUrl}) {
  105. return Container(
  106. width: 60.r,
  107. height: 60.r,
  108. decoration: BoxDecoration(
  109. borderRadius: BorderRadius.circular(8),
  110. gradient: LinearGradient(
  111. begin: Alignment.topCenter,
  112. end: Alignment.bottomCenter,
  113. colors: [Color(0xffebe6ff), Color(0xffffe6fe)],
  114. ),
  115. ),
  116. child: CachedNetworkImage(
  117. imageUrl: imageUrl ?? "",
  118. width: 60.r,
  119. height: 60.r,
  120. fit: BoxFit.cover,
  121. ),
  122. );
  123. }
  124. /// 构建角色信息,包括名称、VIP标识和描述
  125. Widget _buildCharacterInfo(CharacterInfo characterInfo) {
  126. return Expanded(
  127. child: Column(
  128. mainAxisAlignment: MainAxisAlignment.center,
  129. crossAxisAlignment: CrossAxisAlignment.start,
  130. children: [
  131. Row(
  132. children: [
  133. Text(
  134. characterInfo.name ?? "",
  135. style: TextStyle(
  136. color: Colors.black.withAlpha(204),
  137. fontSize: 15.sp,
  138. fontWeight: FontWeight.w500,
  139. ),
  140. ),
  141. SizedBox(width: 4.w),
  142. characterInfo.isVip == true
  143. ? Assets.images.iconCharacterVip.image(
  144. width: 38.w,
  145. height: 16.h,
  146. )
  147. : Container(),
  148. ],
  149. ),
  150. Text(
  151. characterInfo.description ?? "",
  152. softWrap: true,
  153. style: TextStyle(
  154. color: Colors.black.withAlpha(153),
  155. fontSize: 12.sp,
  156. fontWeight: FontWeight.w400,
  157. ),
  158. ),
  159. ],
  160. ),
  161. );
  162. }
  163. /// 按钮
  164. Widget _buildActionButton(CharacterInfo characterInfo) {
  165. return InkWell(
  166. onTap: () {
  167. controller.itemButtonClick(characterInfo);
  168. },
  169. child: Container(
  170. width: 72.w,
  171. height: 28.h,
  172. margin: EdgeInsets.only(left: 8.w),
  173. decoration: BoxDecoration(
  174. borderRadius: BorderRadius.circular(50.r),
  175. gradient:
  176. characterInfo.isAdd == true
  177. ? null
  178. : const LinearGradient(
  179. colors: [Color(0xFF7D46FC), Color(0xFFBC87FF)],
  180. begin: Alignment.topLeft,
  181. end: Alignment.bottomRight,
  182. ),
  183. color: characterInfo.isAdd == true ? const Color(0xFFEDE8FF) : null,
  184. ),
  185. child: Row(
  186. mainAxisAlignment: MainAxisAlignment.center,
  187. children: [
  188. if (characterInfo.isLock == true && characterInfo.isVip == true)
  189. Padding(
  190. padding: EdgeInsets.only(right: 2.w),
  191. child: Assets.images.iconCharacterLock.image(
  192. width: 18.r,
  193. height: 18.r,
  194. ), // 锁定图标
  195. ),
  196. Text(
  197. characterInfo.isLock == true && characterInfo.isVip == true
  198. ? StringName.characterUnlock
  199. : characterInfo.isAdd == true
  200. ? StringName.characterAdded
  201. : StringName.characterAdd,
  202. style: TextStyle(
  203. color:
  204. characterInfo.isAdd == true
  205. ? const Color(0xFF7D46FC)
  206. : Colors.white,
  207. fontSize: 14.sp,
  208. fontWeight: FontWeight.w500,
  209. ),
  210. ),
  211. ],
  212. ),
  213. ),
  214. );
  215. }
  216. }