view.dart 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. import 'package:electronic_assistant/base/base_page.dart';
  2. import 'package:electronic_assistant/utils/expand.dart';
  3. import 'package:flutter/cupertino.dart';
  4. import 'package:flutter/gestures.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:flutter_screenutil/flutter_screenutil.dart';
  7. import 'package:get/get.dart';
  8. import 'package:pull_to_refresh/pull_to_refresh.dart';
  9. import '../../../data/bean/talks.dart';
  10. import '../../../data/consts/Constants.dart';
  11. import '../../../resource/assets.gen.dart';
  12. import '../../../resource/colors.gen.dart';
  13. import '../../../resource/string.gen.dart';
  14. import 'controller.dart';
  15. class HomeTalkView extends BasePage<HomeTalkController> {
  16. const HomeTalkView({super.key});
  17. @override
  18. bool immersive() {
  19. return true;
  20. }
  21. @override
  22. Color backgroundColor() {
  23. return '#F6F5F8'.color;
  24. }
  25. @override
  26. Widget buildBody(BuildContext context) {
  27. return Obx(() {
  28. return SmartRefresher(
  29. controller: controller.refreshController,
  30. enablePullUp: false,
  31. onRefresh: controller.onRefresh,
  32. enablePullDown: true,
  33. child: ListView(
  34. padding: EdgeInsets.only(left: 12.w, top: 4.w, right: 12.w),
  35. children: [
  36. for (var value in controller.talkList.length > 10
  37. ? controller.talkList.sublist(0, 10)
  38. : controller.talkList)
  39. _buildTalkView(value),
  40. _buildSeeMoreView()
  41. ],
  42. ));
  43. });
  44. }
  45. Widget _buildSeeMoreView() {
  46. return Obx(() {
  47. return Visibility(
  48. visible: controller.talkList.isNotEmpty,
  49. child: Container(
  50. alignment: Alignment.center,
  51. padding: EdgeInsets.only(
  52. top: 16.w, bottom: 100.w + Constants.bottomBarHeight),
  53. child: RichText(
  54. text: TextSpan(
  55. text: StringName.homeTalkSeeMoreTxt.tr,
  56. style: TextStyle(
  57. color: ColorName.secondaryTextColor, fontSize: 12.sp),
  58. children: <TextSpan>[
  59. TextSpan(
  60. text: StringName.homeTalkAll.tr,
  61. style: TextStyle(
  62. color: ColorName.colorPrimary, fontSize: 12.sp),
  63. recognizer: TapGestureRecognizer()
  64. ..onTap = () {
  65. controller.onGoTalkSeeAll();
  66. }),
  67. ],
  68. ),
  69. ),
  70. ),
  71. );
  72. });
  73. }
  74. Widget _buildTalkView(TalkBean item) {
  75. return _buildTalkItem(item, onLongPressStart: (details) {
  76. controller.onLongPressTalkItem(item, details);
  77. }, onItemClick: () {
  78. controller.onTalkItemClick(item);
  79. });
  80. }
  81. Widget _buildTalkItem(TalkBean item,
  82. {VoidCallback? onItemClick,
  83. GestureLongPressStartCallback? onLongPressStart}) {
  84. return GestureDetector(
  85. onTap: onItemClick,
  86. onLongPressStart: onLongPressStart,
  87. child: Container(
  88. margin: EdgeInsets.only(bottom: 8.w),
  89. decoration: BoxDecoration(
  90. color: Colors.white,
  91. borderRadius: BorderRadius.all(Radius.circular(12.w)),
  92. ),
  93. child: Stack(
  94. children: [
  95. Padding(
  96. padding: EdgeInsets.symmetric(horizontal: 12.w),
  97. child: Column(
  98. crossAxisAlignment: CrossAxisAlignment.start,
  99. children: [
  100. SizedBox(height: 16.w),
  101. Text(
  102. item.title.value.orEmpty,
  103. style: TextStyle(
  104. fontSize: 15.sp,
  105. color: ColorName.primaryTextColor,
  106. fontWeight: FontWeight.bold),
  107. maxLines: 1,
  108. overflow: TextOverflow.ellipsis,
  109. ),
  110. SizedBox(height: 4.w),
  111. RichText(
  112. maxLines: 2,
  113. overflow: TextOverflow.ellipsis,
  114. text: TextSpan(
  115. children: [
  116. WidgetSpan(
  117. alignment: PlaceholderAlignment.middle,
  118. child: Container(
  119. decoration: BoxDecoration(
  120. gradient: RadialGradient(
  121. center: Alignment.centerRight,
  122. colors: [
  123. "#E7EEFF".toColor(),
  124. "#F4E8FF".toColor()
  125. ],
  126. radius: 2),
  127. borderRadius: BorderRadius.circular(4.w)),
  128. padding: EdgeInsets.symmetric(
  129. horizontal: 5.w, vertical: 2.w),
  130. margin: EdgeInsets.only(right: 4.w),
  131. child: ShaderMask(
  132. shaderCallback: (bounds) {
  133. return LinearGradient(
  134. colors: ['#9075FF'.color, '#4366FF'.color],
  135. ).createShader(bounds);
  136. },
  137. blendMode: BlendMode.srcIn,
  138. child: Text(
  139. StringName.talkSummary.tr,
  140. style: TextStyle(fontSize: 11.sp, height: 1),
  141. ),
  142. ),
  143. ),
  144. ),
  145. TextSpan(
  146. text: item.summary.value.orEmpty,
  147. style: TextStyle(
  148. fontSize: 12.sp, color: '#969699'.color),
  149. ),
  150. ],
  151. ),
  152. ),
  153. SizedBox(height: 6.w),
  154. Row(
  155. crossAxisAlignment: CrossAxisAlignment.center,
  156. children: [
  157. Assets.images.iconTalkHomeSmallRecord
  158. .image(width: 14.w, height: 14.w),
  159. SizedBox(width: 2.w),
  160. Text(item.duration.toFormattedDuration(),
  161. style: TextStyle(
  162. fontSize: 11.sp, color: '#969699'.color)),
  163. SizedBox(width: 2.w),
  164. Text('·',
  165. style: TextStyle(
  166. fontSize: 11.sp, color: '#969699'.color)),
  167. SizedBox(width: 2.w),
  168. Text(item.createTime.orEmpty,
  169. style: TextStyle(
  170. fontSize: 11.sp, color: '#969699'.color)),
  171. ],
  172. ),
  173. SizedBox(height: 15.w)
  174. ],
  175. ),
  176. ),
  177. Visibility(
  178. visible: item.isExample.isTrue,
  179. child: Align(
  180. alignment: Alignment.topRight,
  181. child: Container(
  182. padding:
  183. EdgeInsets.symmetric(vertical: 2.w, horizontal: 10.w),
  184. decoration: BoxDecoration(
  185. color: "#F0F0FA".toColor(),
  186. borderRadius: const BorderRadius.only(
  187. topRight: Radius.circular(12),
  188. bottomLeft: Radius.circular(12))),
  189. child: Text(StringName.homeTalkExample.tr,
  190. style: TextStyle(
  191. height: 1,
  192. fontSize: 12.sp,
  193. color: '#A7ACBF'.color)),
  194. ),
  195. ),
  196. )
  197. ],
  198. )),
  199. );
  200. }
  201. }