character_group_content_view.dart 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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/module/character/content/character_group_content_controller.dart';
  8. import 'package:keyboard/resource/string.gen.dart';
  9. import '../../../data/bean/character_info.dart';
  10. import '../../../resource/assets.gen.dart';
  11. class CharacterGroupContentView
  12. extends BaseView<CharacterGroupContentController> {
  13. const CharacterGroupContentView({super.key});
  14. @override
  15. backgroundColor() => const Color(0xFFF4F2FB);
  16. @override
  17. Widget buildBody(BuildContext context) {
  18. return
  19. Column(
  20. children: [
  21. SizedBox(
  22. height: 8.w,
  23. ),
  24. Expanded(
  25. child: Obx(() {
  26. return EasyRefresh(
  27. controller: controller.refreshController,
  28. header: const ClassicHeader(),
  29. footer: ClassicFooter(
  30. showMessage: false,
  31. noMoreText: StringName.noMoreData,
  32. failedText: StringName.loadFailed,
  33. processedText: StringName.loadCompleted,
  34. processingText: StringName.loading,
  35. ),
  36. onRefresh: null,
  37. // onRefresh: controller.refreshData,
  38. onLoad: controller.loadMoreData,
  39. child: ListView.separated(
  40. padding: EdgeInsets.zero,
  41. itemCount: controller.characterList.length,
  42. itemBuilder: (context, index) {
  43. return _buildListItem(
  44. characterInfo: controller.characterList[index],
  45. );
  46. },
  47. separatorBuilder: (BuildContext context, int index) {
  48. return SizedBox(
  49. width: double.infinity,
  50. height: 10.h,
  51. child: Container(color: const Color(0xFFF4F2FB)),
  52. );
  53. },
  54. ),
  55. );
  56. }),
  57. ),
  58. ],
  59. );
  60. }
  61. Widget _buildListItem({required CharacterInfo characterInfo}) {
  62. return GestureDetector(
  63. onTap: () {
  64. controller.itemButtonClick(characterInfo);
  65. },
  66. child: Container(
  67. margin: EdgeInsets.symmetric(horizontal: 16.w),
  68. padding: EdgeInsets.all(14.r),
  69. decoration: ShapeDecoration(
  70. color: Colors.white,
  71. shape: RoundedRectangleBorder(
  72. borderRadius: BorderRadius.circular(12.r),
  73. ),
  74. ),
  75. child: Row(
  76. children: [
  77. _buildAvatar(imageUrl: characterInfo.imageUrl),
  78. SizedBox(width: 8.w),
  79. _buildCharacterInfo(characterInfo),
  80. _buildActionButton(characterInfo),
  81. ],
  82. ),
  83. ),
  84. );
  85. }
  86. /// 角色头像
  87. Widget _buildAvatar({required String? imageUrl}) {
  88. return Container(
  89. width: 60.r,
  90. height: 60.r,
  91. decoration: BoxDecoration(
  92. borderRadius: BorderRadius.circular(8),
  93. gradient: LinearGradient(
  94. begin: Alignment.topCenter,
  95. end: Alignment.bottomCenter,
  96. colors: [Color(0xffebe6ff), Color(0xffffe6fe)],
  97. ),
  98. ),
  99. child: CachedNetworkImage(
  100. imageUrl: imageUrl ?? "",
  101. width: 60.r,
  102. height: 60.r,
  103. fit: BoxFit.cover,
  104. ),
  105. );
  106. }
  107. /// 构建角色信息,包括名称、VIP标识和描述
  108. Widget _buildCharacterInfo(CharacterInfo characterInfo) {
  109. return Expanded(
  110. child: Column(
  111. mainAxisAlignment: MainAxisAlignment.center,
  112. crossAxisAlignment: CrossAxisAlignment.start,
  113. children: [
  114. Row(
  115. children: [
  116. Text(
  117. characterInfo.name ?? "",
  118. style: TextStyle(
  119. color: Colors.black.withAlpha(204),
  120. fontSize: 15.sp,
  121. fontWeight: FontWeight.w500,
  122. ),
  123. ),
  124. SizedBox(width: 4.w),
  125. characterInfo.isVip == true
  126. ? Assets.images.iconCharacterVip.image(
  127. width: 38.w,
  128. height: 16.h,
  129. )
  130. : Container(),
  131. ],
  132. ),
  133. Text(
  134. characterInfo.description ?? "",
  135. softWrap: true,
  136. style: TextStyle(
  137. color: Colors.black.withAlpha(153),
  138. fontSize: 12.sp,
  139. fontWeight: FontWeight.w400,
  140. ),
  141. ),
  142. ],
  143. ),
  144. );
  145. }
  146. /// 按钮
  147. Widget _buildActionButton(CharacterInfo characterInfo) {
  148. return InkWell(
  149. onTap: () {
  150. controller.itemButtonClick(characterInfo);
  151. },
  152. child: Container(
  153. width: 72.w,
  154. height: 28.h,
  155. margin: EdgeInsets.only(left: 8.w),
  156. decoration: BoxDecoration(
  157. borderRadius: BorderRadius.circular(50.r),
  158. gradient:
  159. characterInfo.isAdd == true
  160. ? null
  161. : const LinearGradient(
  162. colors: [Color(0xFF7D46FC), Color(0xFFBC87FF)],
  163. begin: Alignment.topLeft,
  164. end: Alignment.bottomRight,
  165. ),
  166. color: characterInfo.isAdd == true ? const Color(0xFFEDE8FF) : null,
  167. ),
  168. child: Row(
  169. mainAxisAlignment: MainAxisAlignment.center,
  170. children: [
  171. if (characterInfo.isLock == true && characterInfo.isVip == true)
  172. Padding(
  173. padding: EdgeInsets.only(right: 2.w),
  174. child: Assets.images.iconCharacterLock.image(
  175. width: 18.r,
  176. height: 18.r,
  177. ), // 锁定图标
  178. ),
  179. Text(
  180. characterInfo.isLock == true && characterInfo.isVip == true
  181. ? StringName.characterUnlock
  182. : characterInfo.isAdd == true
  183. ? StringName.characterAdded
  184. : StringName.characterAdd,
  185. style: TextStyle(
  186. color:
  187. characterInfo.isAdd == true
  188. ? const Color(0xFF7D46FC)
  189. : Colors.white,
  190. fontSize: 14.sp,
  191. fontWeight: FontWeight.w500,
  192. ),
  193. ),
  194. ],
  195. ),
  196. ),
  197. );
  198. }
  199. }