services_main_page.dart 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import 'package:cs_resources/generated/assets.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:auto_route/auto_route.dart';
  4. import 'package:flutter/rendering.dart';
  5. import 'package:flutter_hooks/flutter_hooks.dart';
  6. import 'package:hooks_riverpod/hooks_riverpod.dart';
  7. import 'package:plugin_basic/provider/user_config/user_config_service.dart';
  8. import 'package:router/ext/auto_router_extensions.dart';
  9. import 'package:shared/utils/color_utils.dart';
  10. import 'package:shared/utils/log_utils.dart';
  11. import 'package:widgets/custom_sliver_persistent_header_delegate.dart';
  12. import 'package:widgets/my_load_image.dart';
  13. import 'package:widgets/ext/ex_widget.dart';
  14. import 'package:widgets/my_text_view.dart';
  15. import 'package:widgets/my_appbar.dart';
  16. import 'package:cs_resources/theme/app_colors_theme.dart';
  17. import 'package:widgets/widget_export.dart';
  18. import '../../router/page/services_page_router.dart';
  19. import 'inProgress/in_progress_page.dart';
  20. import 'repair/repair_page.dart';
  21. import 'services_page.dart';
  22. enum ServicesType {
  23. cleaning,
  24. repair,
  25. }
  26. @RoutePage()
  27. class ServicesMainPage extends HookConsumerWidget {
  28. ServicesMainPage({Key? key}) : super(key: key);
  29. //启动当前页面
  30. static void startInstance({BuildContext? context}) {
  31. if (context != null) {
  32. context.router.push( ServicesMainPageRoute());
  33. } else {
  34. appRouter.push( ServicesMainPageRoute());
  35. }
  36. }
  37. @override
  38. Widget build(BuildContext context, WidgetRef ref) {
  39. useEffect(() {
  40. // 监听窗口
  41. }, []);
  42. useEffect(() {
  43. Log.d("ServicesMainPage initState");
  44. // 延迟监听
  45. }, []);
  46. return Scaffold(
  47. appBar: MyAppBar.appBar(
  48. context,
  49. "ServicesMain",
  50. backgroundColor: context.appColors.whiteBG,
  51. ),
  52. backgroundColor: ColorUtils.string2Color("#F2F3F6"),
  53. body: Container(
  54. child: GridView.count(
  55. crossAxisCount: 2,
  56. padding: EdgeInsets.all(10),
  57. mainAxisSpacing: 10,
  58. crossAxisSpacing: 10,
  59. childAspectRatio: 165/146,
  60. children: [
  61. _buildServiceCard(
  62. context,
  63. ServicesType.cleaning,
  64. Assets.serviceHomeServices,
  65. "Home Services",
  66. 102.5,
  67. 82.5,
  68. ServicesPage.startInstance,
  69. ),
  70. _buildServiceCard(
  71. context,
  72. ServicesType.repair,
  73. Assets.serviceMaintenance,
  74. "Maintenance",
  75. 129,
  76. 107.5,
  77. RepairPage.startInstance,
  78. ),
  79. ]
  80. ),
  81. ),
  82. );
  83. }
  84. Widget _buildServiceCard(
  85. BuildContext context,
  86. ServicesType type,
  87. String imagePath,
  88. String title,
  89. double iconWidth,
  90. double iconHeight,
  91. Function() onTap,
  92. ) {
  93. return Container(
  94. margin: EdgeInsets.all(10),
  95. decoration: BoxDecoration(
  96. color: context.appColors.whiteBG,
  97. borderRadius: BorderRadius.circular(10),
  98. boxShadow: [
  99. BoxShadow(
  100. color: context.appColors.whiteBG,
  101. blurRadius: 5,
  102. offset: Offset(0, 3),
  103. ),
  104. ],
  105. ),
  106. child: Stack(
  107. children: [
  108. Padding(
  109. padding: const EdgeInsets.only(left: 15, right:15.0, top: 10,bottom: 10),
  110. child: MyTextView(
  111. title,
  112. fontSize: 16,
  113. isFontMedium: true,
  114. alignment: Alignment.topLeft,
  115. ),
  116. ),
  117. Positioned(
  118. bottom: 0,
  119. right: 0,
  120. child: Container(
  121. child: MyLoadImage(
  122. imagePath,
  123. fit: BoxFit.cover,
  124. width: iconWidth,
  125. height: iconHeight,
  126. ),
  127. ),
  128. )
  129. ]
  130. )
  131. ).onTap((){
  132. if(type == ServicesType.cleaning){
  133. ServicesPage.startInstance();
  134. }else if(type == ServicesType.repair){
  135. RepairPage.startInstance();
  136. }
  137. });
  138. }
  139. }