character_group_content_view.dart 6.2 KB

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