custom_character_add_view.dart 6.8 KB

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