custom_character_add_view.dart 6.8 KB

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