property_sale_page.dart 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import 'package:cpt_property/modules/property/page/property_page.dart';
  2. import 'package:cs_resources/theme/app_colors_theme.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:auto_route/auto_route.dart';
  5. import 'package:flutter_hooks/flutter_hooks.dart';
  6. import 'package:hooks_riverpod/hooks_riverpod.dart';
  7. import 'package:router/ext/auto_router_extensions.dart';
  8. import 'package:shared/utils/log_utils.dart';
  9. import 'package:shared/utils/color_utils.dart';
  10. import 'package:widgets/ext/ex_widget.dart';
  11. import 'package:widgets/load_state_layout.dart';
  12. import 'package:widgets/my_load_image.dart';
  13. import 'package:widgets/my_text_view.dart';
  14. import 'package:widgets/widget_export.dart';
  15. import 'package:cs_resources/generated/assets.dart';
  16. import '../../../router/page/property_page_router.dart';
  17. import '../vm/property_sale_vm.dart';
  18. @RoutePage()
  19. class PropertySalePage extends HookConsumerWidget {
  20. const PropertySalePage({Key? key}) : super(key: key);
  21. //启动当前页面
  22. static void startInstance({BuildContext? context}) {
  23. if (context != null) {
  24. context.router.push(const PropertySalePageRoute());
  25. } else {
  26. appRouter.push(const PropertySalePageRoute());
  27. }
  28. }
  29. Widget _buildItemLeftSection(BuildContext context,WidgetRef ref, item, _vm) {
  30. return Container(
  31. // color: Colors.blue,
  32. child:
  33. MyTextView(
  34. item['title'],
  35. fontSize: 16,
  36. textColor: context.appColors.textBlack,
  37. isFontMedium: true,
  38. ),
  39. ).marginOnly(right: 17.5);
  40. }
  41. Widget _buildItemRightSection(BuildContext context,WidgetRef ref, item, _vm) {
  42. return Container(
  43. color: Colors.white,
  44. child: TextButton(
  45. onPressed: (){},
  46. style: TextButton.styleFrom(
  47. foregroundColor: context.appColors.textBlack,
  48. backgroundColor: ColorUtils.string2Color('#EFF3FF'), // 背景颜色
  49. minimumSize: const Size(91.5, 44), // 最小宽度和高度
  50. padding: const EdgeInsets.symmetric(horizontal: 11.0, vertical: 14), // 内边距
  51. shape: RoundedRectangleBorder(
  52. borderRadius: BorderRadius.circular(5), // 圆角
  53. side: BorderSide(
  54. color: ColorUtils.string2Color('#EFF3FF'),
  55. width: 1.0,
  56. ), // 边框
  57. ),
  58. ),
  59. child:MyTextView(
  60. item['price'],
  61. fontSize: 17,
  62. textColor: context.appColors.textBlack,
  63. isFontMedium: true,
  64. ),
  65. ),
  66. );
  67. }
  68. // listitem
  69. Widget _buildSaleItem(BuildContext context,WidgetRef ref, item, _vm) {
  70. return Container(
  71. decoration: BoxDecoration(
  72. color: context.appColors.backgroundWhite,
  73. // borderRadius: BorderRadius.circular(5),
  74. ),
  75. child: Row(
  76. mainAxisAlignment: MainAxisAlignment.center,
  77. crossAxisAlignment: CrossAxisAlignment.center,
  78. mainAxisSize: MainAxisSize.max,
  79. children: [
  80. Container(
  81. width: MediaQuery.of(context).size.width - 30,
  82. height: 100,
  83. margin: const EdgeInsets.only(left: 15,right: 15,top: 12.5),
  84. child: Row(
  85. mainAxisAlignment: MainAxisAlignment.start,
  86. crossAxisAlignment: CrossAxisAlignment.center,
  87. children: [
  88. Expanded(child: _buildItemLeftSection(context, ref, item, _vm)),
  89. SizedBox(
  90. width: 120,
  91. child: _buildItemRightSection(context, ref, item, _vm),
  92. ),
  93. ],
  94. ),
  95. ),
  96. ],
  97. ).onTap((){
  98. // 去详情
  99. _vm.goNewsDetail(item);
  100. }),
  101. ).border(color: context.appColors.dividerDefault, bottom: 0.5);
  102. }
  103. @override
  104. Widget build(BuildContext context, WidgetRef ref) {
  105. final _vm = ref.read(propertySaleVmProvider.notifier);
  106. final state = ref.watch(propertySaleVmProvider);
  107. useEffect(() {
  108. // 组件挂载时执行 - 执行接口请求
  109. Future.microtask(() => _vm.initPageData());
  110. return () {
  111. // 组件卸载时执行
  112. Log.d("property_sale_page 组件卸载时执行");
  113. };
  114. }, []);
  115. return Scaffold(
  116. // appBar: AppBar(title: Text("资产")),
  117. backgroundColor: ColorUtils.string2Color("#F2F3F6"),
  118. body: EasyRefresh(
  119. controller: _vm.refreshController,
  120. // 上拉加载
  121. onLoad: () async{
  122. Log.d("----onLoad");
  123. _vm.loadMore();
  124. },
  125. // 下拉刷新
  126. onRefresh: () async{
  127. Log.d("----onRefresh");
  128. _vm.onRefresh();
  129. },
  130. child: LoadStateLayout(
  131. state: state.loadingState,
  132. errorMessage: state.errorMessage,
  133. errorRetry: () {
  134. _vm.retryRequest();
  135. },
  136. successSliverWidget: [
  137. SliverList(
  138. delegate: SliverChildBuilderDelegate(
  139. (context, index){
  140. return _buildSaleItem(context, ref, state.list[index], _vm);
  141. },
  142. childCount: state.list.length
  143. )
  144. )
  145. ],
  146. ),
  147. ).marginOnly(top: 5, bottom: 5),
  148. );
  149. }
  150. }