news_page.dart 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. import 'dart:io';
  2. import 'dart:ui';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter/src/widgets/framework.dart';
  5. import 'package:flutter/widgets.dart';
  6. import 'package:flutter_screenutil/flutter_screenutil.dart';
  7. import 'package:get/get.dart';
  8. import 'package:get/get_core/src/get_main.dart';
  9. import 'package:location/base/base_page.dart';
  10. import 'package:location/utils/common_expand.dart';
  11. import '../../resource/assets.gen.dart';
  12. import '../../resource/colors.gen.dart';
  13. import '../../resource/string.gen.dart';
  14. import '../../router/app_pages.dart';
  15. import '../../widget/common_view.dart';
  16. import 'news_controller.dart';
  17. import 'news_list_item.dart';
  18. class NewsPage extends BasePage<NewsController> {
  19. const NewsPage({super.key});
  20. static void start() {
  21. Get.toNamed(RoutePath.news);
  22. }
  23. @override
  24. bool immersive() {
  25. return true;
  26. }
  27. @override
  28. Widget buildBody(BuildContext context) {
  29. return Stack(
  30. children: [
  31. Assets.images.bgPageBackground.image(width: double.infinity),
  32. Positioned(
  33. top: 24.w,
  34. right: 19.w,
  35. child: SafeArea(child: Obx(() {
  36. return Visibility(
  37. visible: controller.waitingNewsCount > 0 ||
  38. controller.messageList.isNotEmpty,
  39. child: Opacity(
  40. opacity: 1 - controller.opacity,
  41. child: Assets.images.iconNews.image(width: 118.w)),
  42. );
  43. }))),
  44. SafeArea(
  45. child: Column(
  46. children: [
  47. buildHeadView(),
  48. Obx(() {
  49. return Expanded(
  50. child: controller.waitingNewsCount == 0 &&
  51. controller.messageList.isEmpty
  52. ? buildNoMessageView()
  53. : buildHasMessageView());
  54. }),
  55. SizedBox(
  56. height:18.w + 46.w + 10.w,
  57. )
  58. ],
  59. ),
  60. ),
  61. Positioned(
  62. bottom: MediaQuery.of(Get.context!).padding.bottom + 18.w,
  63. left: 0,
  64. right: 0,
  65. height: 46.w,
  66. child: GestureDetector(
  67. onTap: () {
  68. controller.onAddJumpToAddNewFriend();
  69. },
  70. child: Container(
  71. decoration: BoxDecoration(
  72. color: "#7B7DFF".color,
  73. borderRadius: BorderRadius.circular(10.w),
  74. ),
  75. margin: EdgeInsets.symmetric(horizontal: 15.w),
  76. height: 46.w,
  77. alignment: Alignment.center,
  78. child: Text("添加好友",
  79. style: TextStyle(
  80. fontSize: 14.sp,
  81. color: '#FFFFFF'.color,
  82. fontWeight: FontWeight.w500)
  83. ),
  84. ),
  85. )),
  86. ],
  87. );
  88. }
  89. CustomScrollView buildHasMessageView() {
  90. return CustomScrollView(
  91. controller: controller.scrollController,
  92. slivers: [
  93. buildSliverTitle(),
  94. buildSliverWaiting(),
  95. Obx(() {
  96. return SliverList.builder(
  97. itemBuilder: buildNewsItem,
  98. itemCount: controller.messageList.length);
  99. })
  100. ],
  101. );
  102. }
  103. SliverToBoxAdapter buildSliverTitle() {
  104. return SliverToBoxAdapter(
  105. child: Column(
  106. crossAxisAlignment: CrossAxisAlignment.start,
  107. children: [
  108. SizedBox(height: 18.w),
  109. Padding(
  110. padding: EdgeInsets.only(left: 12.w),
  111. child: Text(StringName.newsTitle,
  112. style: TextStyle(
  113. fontSize: 16.sp,
  114. color: ColorName.black90,
  115. fontWeight: FontWeight.bold)),
  116. ),
  117. SizedBox(height: 10.w),
  118. ],
  119. ));
  120. }
  121. Widget buildHeadView() {
  122. return Container(
  123. margin: EdgeInsets.symmetric(horizontal: 12.w, vertical: 14.w),
  124. child: Row(
  125. crossAxisAlignment: CrossAxisAlignment.center,
  126. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  127. children: [
  128. GestureDetector(
  129. onTap: controller.back, child: CommonView.getBackBtnView()),
  130. Obx(() {
  131. return Opacity(
  132. opacity: controller.opacity,
  133. child: Text(StringName.newsTitle,
  134. style: TextStyle(
  135. fontSize: 16.sp,
  136. color: ColorName.black90,
  137. fontWeight: FontWeight.bold)),
  138. );
  139. }),
  140. GestureDetector(
  141. onTap: controller.newsClick,
  142. child:
  143. Assets.images.iconFriendNews.image(width: 24.w, height: 24.w))
  144. ],
  145. ),
  146. );
  147. }
  148. SliverToBoxAdapter buildSliverWaiting() {
  149. return SliverToBoxAdapter(child: Obx(() {
  150. if (controller.waitingNewsCount == 0) {
  151. return SizedBox.shrink();
  152. }
  153. return GestureDetector(
  154. onTap: () => controller.onMessageWaitingClick(),
  155. child: buildMessageItem(Assets.images.iconNewsItem.provider(),
  156. title: StringName.newsRequestTitle,
  157. content: StringName.newsRequestDesc,
  158. contentTextStyle:
  159. TextStyle(fontSize: 12.sp, color: ColorName.black60),
  160. createTime: controller.latestFriendRequest?.createTime ?? 0,
  161. statusWidget: Container(
  162. height: 16.w,
  163. constraints: BoxConstraints(
  164. minWidth: 16.w,
  165. ),
  166. padding: EdgeInsets.symmetric(horizontal: 2.w),
  167. decoration: BoxDecoration(
  168. color: '#FF333D'.color,
  169. borderRadius: BorderRadius.circular(100),
  170. ),
  171. child: Center(
  172. child: Text('${controller.waitingNewsCount}',
  173. textAlign: TextAlign.center,
  174. style: TextStyle(
  175. fontSize: 10.sp, color: ColorName.white, height: 1)),
  176. ),
  177. )),
  178. );
  179. }));
  180. }
  181. Widget buildNewsItem(BuildContext context, int index) {
  182. final item = controller.messageList[index];
  183. return GestureDetector(
  184. onLongPress: () {
  185. controller.onUserIsLongEventClick(index);
  186. },
  187. child: Obx(() {
  188. return buildMessageInfoItem(
  189. item, (info) => controller.onMessageFunClick(info),
  190. isShowReportButton: (controller.isLongTapIndex.value == index) && Platform.isIOS && (item.type == 3 || item.type == 4),
  191. onReportEvent: (item.type == 3 || item.type == 4) ? controller.onReportEventClick : null
  192. );
  193. }),
  194. );
  195. }
  196. Widget buildNoMessageView() {
  197. return Align(
  198. alignment: Alignment(0, -0.1),
  199. child: IntrinsicHeight(
  200. child: Column(
  201. children: [
  202. Assets.images.iconNews.image(width: 150.w),
  203. SizedBox(height: 9.w),
  204. Text(StringName.messageNoData,
  205. style: TextStyle(fontSize: 16.sp, color: ColorName.black60))
  206. ],
  207. ),
  208. ),
  209. );
  210. }
  211. }