facility_book_screen.dart 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 SizedBox(
  26. width: double.infinity,
  27. height: double.infinity,
  28. child: EasyRefresh(
  29. controller: viewModel.refreshController,
  30. onRefresh: viewModel.onRefresh,
  31. child: LoadStateLayout(
  32. state: state.loadingState,
  33. errorMessage: state.errorMessage,
  34. errorRetry: () {
  35. viewModel.retryRequest();
  36. },
  37. successSliverWidget: [
  38. SliverList(
  39. delegate: SliverChildBuilderDelegate(
  40. (context, index) {
  41. return FacilityBookItem(index: index, item: state.datas[index]).onTap(() {
  42. FacilityBookingPage.startInstance(
  43. context: context,
  44. facilityEntity: state.datas[index],
  45. );
  46. });
  47. },
  48. childCount: state.datas.length,
  49. ))
  50. ],
  51. ),
  52. ).marginOnly(top: 5, bottom: 5),
  53. );
  54. }
  55. }