property_sale_page.dart 5.0 KB

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