character_group_content_view.dart 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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:keyboard/base/base_view.dart';
  6. import 'package:get/get.dart';
  7. import 'package:keyboard/data/repository/account_repository.dart';
  8. import 'package:keyboard/module/character/content/character_group_content_controller.dart';
  9. import 'package:keyboard/resource/string.gen.dart';
  10. import '../../../data/bean/character_group_info.dart';
  11. import '../../../data/bean/character_info.dart';
  12. import '../../../data/bean/keyboard_info.dart';
  13. import '../../../data/repository/characters_repository.dart';
  14. import '../../../resource/assets.gen.dart';
  15. import 'package:get_it/get_it.dart';
  16. class CharacterGroupContentView
  17. extends BaseView<CharacterGroupContentController> {
  18. final KeyboardInfo currentKeyboardInfo;
  19. final CharacterGroupInfo currentCharacterGroupInfo;
  20. @override
  21. String? get tag => "CharacterGroupContentController${currentKeyboardInfo.id}${currentCharacterGroupInfo.id}";
  22. const CharacterGroupContentView({super.key, required this.currentKeyboardInfo,required this.currentCharacterGroupInfo});
  23. @override
  24. backgroundColor() => const Color(0xFFF4F2FB);
  25. @override
  26. Widget buildBody(BuildContext context) {
  27. Get.put(
  28. CharacterGroupContentController(
  29. GetIt.instance.get<CharactersRepository>(),
  30. GetIt.instance.get<AccountRepository>(),
  31. currentCharacterGroupInfo: currentCharacterGroupInfo,
  32. currentKeyboardInfo: currentKeyboardInfo,
  33. ),
  34. tag: tag,
  35. );
  36. return
  37. Column(
  38. children: [
  39. SizedBox(
  40. height: 8.w,
  41. ),
  42. Expanded(
  43. child: Obx(() {
  44. return EasyRefresh(
  45. controller: controller.refreshController,
  46. header: const ClassicHeader(),
  47. footer: ClassicFooter(
  48. showMessage: false,
  49. noMoreText: StringName.noMoreData,
  50. failedText: StringName.loadFailed,
  51. processedText: StringName.loadCompleted,
  52. processingText: StringName.loading,
  53. ),
  54. onRefresh: null,
  55. // onRefresh: controller.refreshData,
  56. onLoad: controller.loadMoreData,
  57. child: ListView.separated(
  58. padding: EdgeInsets.zero,
  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. margin: EdgeInsets.symmetric(horizontal: 16.w),
  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. }