character_group_content_view.dart 6.1 KB

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