character_group_content_view.dart 6.3 KB

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