facility_book_screen.dart 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import 'package:auto_route/auto_route.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_hooks/flutter_hooks.dart';
  4. import 'package:hooks_riverpod/hooks_riverpod.dart';
  5. import 'package:shared/utils/log_utils.dart';
  6. import 'package:widgets/ext/ex_widget.dart';
  7. import 'package:widgets/load_state_layout.dart';
  8. import 'package:widgets/widget_export.dart';
  9. import '../../booking/facility_booking_page.dart';
  10. import 'facility_book_view_model.dart';
  11. import 'item_facility_book.dart';
  12. @RoutePage()
  13. class FacilityBookScreen extends HookConsumerWidget {
  14. @override
  15. Widget build(BuildContext context, WidgetRef ref) {
  16. final viewModel = ref.read(facilityBookViewModelProvider.notifier);
  17. final state = ref.watch(facilityBookViewModelProvider);
  18. useEffect(() {
  19. // 组件挂载时执行 - 执行接口请求
  20. Future.microtask(() => viewModel.fetchList());
  21. return () {
  22. // 组件卸载时执行
  23. };
  24. }, []);
  25. return Container(
  26. width: double.infinity,
  27. height: double.infinity,
  28. child: EasyRefresh(
  29. controller: viewModel.refreshController,
  30. onRefresh: viewModel.onRefresh,
  31. onLoad: viewModel.loadMore,
  32. child: LoadStateLayout(
  33. state: state.loadingState,
  34. errorMessage: state.errorMessage,
  35. errorRetry: () {
  36. viewModel.retryRequest();
  37. },
  38. successSliverWidget: [
  39. SliverList(
  40. delegate: SliverChildBuilderDelegate(
  41. (context, index) {
  42. return FacilityBookItem(index: index, item: state.datas[index]).onTap(() {
  43. FacilityBookingPage.startInstance(context: context);
  44. });
  45. },
  46. childCount: state.datas.length,
  47. ))
  48. ],
  49. ),
  50. ).marginOnly(top: 5, bottom: 5),
  51. );
  52. }
  53. }