character_tab_group_content_view.dart 7.0 KB

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