character_group_content_view.dart 6.2 KB

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