facility_active_screen.dart 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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:widgets/ext/ex_widget.dart';
  6. import 'package:widgets/load_state_layout.dart';
  7. import 'package:widgets/widget_export.dart';
  8. import '../../detail/facility_detail_page.dart';
  9. import 'facility_active_view_model.dart';
  10. import 'item_facility_active.dart';
  11. @RoutePage()
  12. class FacilityActiveScreen extends HookConsumerWidget {
  13. @override
  14. Widget build(BuildContext context, WidgetRef ref) {
  15. final viewModel = ref.read(facilityActiveViewModelProvider.notifier);
  16. final state = ref.watch(facilityActiveViewModelProvider);
  17. useEffect(() {
  18. // 组件挂载时执行 - 执行接口请求
  19. Future.microtask(() => viewModel.fetchList());
  20. return () {
  21. // 组件卸载时执行
  22. };
  23. }, []);
  24. return Container(
  25. width: double.infinity,
  26. height: double.infinity,
  27. child: EasyRefresh(
  28. controller: viewModel.refreshController,
  29. onRefresh: viewModel.onRefresh,
  30. onLoad: viewModel.loadMore,
  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 FacilityActiveItem(index: index, item: state.datas[index]).onTap((){
  42. FacilityDetailPage.startInstance(context: context);
  43. });
  44. },
  45. childCount: state.datas.length,
  46. ))
  47. ],
  48. ),
  49. ).marginOnly(top: 5, bottom: 5),
  50. );
  51. }
  52. }