services_page.dart 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. import 'package:shared/utils/log_utils.dart';
  2. import 'package:cs_resources/generated/assets.dart';
  3. import 'package:cs_resources/theme/app_colors_theme.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:auto_route/auto_route.dart';
  6. import 'package:flutter_hooks/flutter_hooks.dart';
  7. import 'package:hooks_riverpod/hooks_riverpod.dart';
  8. import 'package:router/ext/auto_router_extensions.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_appbar.dart';
  13. import 'package:widgets/my_load_image.dart';
  14. import 'package:widgets/widget_export.dart';
  15. import '../../../router/page/services_page_router.dart';
  16. import 'services_view_model.dart';
  17. @RoutePage()
  18. class ServicesPage extends HookConsumerWidget {
  19. const ServicesPage({Key? key}) : super(key: key);
  20. //启动当前页面
  21. static void startInstance({BuildContext? context}) {
  22. if (context != null) {
  23. context.router.push(const ServicesPageRoute());
  24. } else {
  25. appRouter.push(const ServicesPageRoute());
  26. }
  27. }
  28. Widget _buildTop(BuildContext context, WidgetRef ref, _vm) {
  29. // List itemsList = _vm.state.list.toList();
  30. return Container(
  31. color: ColorUtils.string2Color('#FFFFFF'),
  32. child: Column(children: [
  33. Container(
  34. width: double.infinity,
  35. height: 160,
  36. decoration: const BoxDecoration(
  37. image: DecorationImage(
  38. image: AssetImage(
  39. 'packages/cs_resources/${Assets.propertyHomeLoanBg}'),
  40. fit: BoxFit.fill, // 设置图片平铺
  41. ),
  42. ),
  43. ).marginOnly(bottom: 15),
  44. Row(
  45. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  46. crossAxisAlignment: CrossAxisAlignment.center,
  47. children: [
  48. const Text(
  49. 'Home Services!',
  50. style: TextStyle(
  51. fontSize: 16.0,
  52. color: Colors.black,
  53. fontWeight: FontWeight.w400), // 设置字体大小
  54. ),
  55. TextButton(
  56. onPressed: () {
  57. _vm.doDeleteAccount();
  58. },
  59. style: TextButton.styleFrom(
  60. foregroundColor: Colors.black,
  61. backgroundColor: ColorUtils.string2Color('#4161D0'), // 背景颜色
  62. minimumSize: const Size(70, 30), // 最小宽度和高度
  63. padding: const EdgeInsets.symmetric(
  64. horizontal: 11.0, vertical: 9), // 内边距
  65. shape: RoundedRectangleBorder(
  66. borderRadius: BorderRadius.circular(5), // 圆角
  67. side: BorderSide(
  68. color: ColorUtils.string2Color('#4161D0'),
  69. width: 1.0,
  70. ), // 边框
  71. ),
  72. ),
  73. child: const Text(
  74. 'Filter',
  75. style: const TextStyle(
  76. color: Colors.white,
  77. ),
  78. ),
  79. ),
  80. ],
  81. ),
  82. ])).paddingOnly(top: 10, left: 15, right: 15);
  83. }
  84. Widget _buildItem(BuildContext context, WidgetRef ref, _vm, item) {
  85. return Container(
  86. width: MediaQuery.of(context).size.width / 2 - 25,
  87. height: 146,
  88. decoration: const BoxDecoration(
  89. color: Colors.white,
  90. borderRadius: BorderRadius.all(Radius.circular(6.0)),
  91. boxShadow: [
  92. BoxShadow(
  93. color: Color.fromRGBO(184, 191, 217, 0.3), blurRadius: 6)
  94. ],
  95. ),
  96. child: Column(
  97. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  98. children: [
  99. Row(
  100. crossAxisAlignment: CrossAxisAlignment.start,
  101. children: [
  102. Expanded(
  103. child: Text(
  104. maxLines: 2, // 设置最大行数为2
  105. overflow: TextOverflow.ellipsis, // 超出部分用省略号表示
  106. item['title'],
  107. style: const TextStyle(
  108. fontSize: 16.0,
  109. color: Colors.black,
  110. fontWeight: FontWeight.w700),
  111. ),
  112. )
  113. ],
  114. ),
  115. Row(
  116. mainAxisAlignment: MainAxisAlignment.end,
  117. children: [
  118. MyAssetImage(
  119. item['price'],
  120. width: 110,
  121. height: 80,
  122. )
  123. ],
  124. ),
  125. ],
  126. ).paddingOnly(top: 15, left: 15))
  127. .marginOnly(bottom: 15);
  128. }
  129. // list
  130. Widget _buildSaleList(BuildContext context, WidgetRef ref, _vm) {
  131. List itemsList = _vm.state.list.toList();
  132. return ListView.builder(
  133. itemCount: itemsList.length,
  134. itemBuilder: (context, index) {
  135. bool noLast = !(index == itemsList.length - 1);
  136. bool isLast = index == itemsList.length - 1;
  137. if (index % 2 == 0 && noLast) {
  138. return Row(
  139. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  140. children: [
  141. _buildItem(context, ref, _vm, itemsList[index]),
  142. _buildItem(context, ref, _vm, itemsList[index + 1]),
  143. ],
  144. );
  145. } else if (index % 2 != 0 && noLast) {
  146. return Row();
  147. } else if (index % 2 != 0 && isLast) {
  148. return Row();
  149. } else {
  150. return Row(
  151. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  152. children: [
  153. _buildItem(context, ref, _vm, itemsList[index]),
  154. ],
  155. );
  156. }
  157. // _buildSaleItem(context, ref, itemsList[index], _vm);
  158. },
  159. );
  160. }
  161. @override
  162. Widget build(BuildContext context, WidgetRef ref) {
  163. final state = ref.watch(servicesVmProvider);
  164. final _vm = ref.read(servicesVmProvider.notifier);
  165. return Scaffold(
  166. appBar: MyAppBar.appBar(
  167. context,
  168. "Service",
  169. backgroundColor: context.appColors.whiteBG,
  170. ),
  171. body: Container(
  172. child: Column(
  173. children: [
  174. _buildTop(context, ref, _vm),
  175. Expanded(
  176. child: EasyRefresh(
  177. // 上拉加载
  178. onLoad: () async {
  179. Log.d("----onLoad");
  180. _vm.onLoadData();
  181. },
  182. // 下拉刷新
  183. onRefresh: () async {
  184. Log.d("----onRefresh");
  185. _vm.refreshListData();
  186. },
  187. child: Container(
  188. color: ColorUtils.string2Color('#F2F3F6'),
  189. padding: const EdgeInsets.only(
  190. bottom: 15, left: 15, right: 15, top: 15),
  191. child: _buildSaleList(context, ref, _vm)),
  192. ),
  193. )
  194. ],
  195. ),
  196. ),
  197. );
  198. }
  199. }