feedback_progress.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 '../item_feedback.dart';
  10. import 'feedback_progress_view_model.dart';
  11. @RoutePage()
  12. class FeedbackProgressScreen extends HookConsumerWidget {
  13. @override
  14. Widget build(BuildContext context, WidgetRef ref) {
  15. final viewModel = ref.read(feedbackProgressViewModelProvider.notifier);
  16. final state = ref.watch(feedbackProgressViewModelProvider);
  17. useEffect(() {
  18. // 组件挂载时执行 - 执行接口请求
  19. Future.microtask(() => viewModel.fetchList());
  20. return () {
  21. // 组件卸载时执行
  22. Log.d("FeedbackProgressScreen 组件卸载时执行");
  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 FeedbackItem(index: index, item: state.datas[index]);
  43. },
  44. childCount: state.datas.length,
  45. ))
  46. ],
  47. ),
  48. ).marginOnly(top: 5, bottom: 5),
  49. );
  50. }
  51. }