feedback_progress.dart 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 '../detail/feedback_detail_page.dart';
  10. import '../item_feedback.dart';
  11. import 'feedback_progress_view_model.dart';
  12. @RoutePage()
  13. class FeedbackProgressScreen extends HookConsumerWidget {
  14. @override
  15. Widget build(BuildContext context, WidgetRef ref) {
  16. final viewModel = ref.read(feedbackProgressViewModelProvider.notifier);
  17. final state = ref.watch(feedbackProgressViewModelProvider);
  18. useEffect(() {
  19. // 组件挂载时执行 - 执行接口请求
  20. Future.microtask(() => viewModel.fetchList());
  21. return () {
  22. // 组件卸载时执行
  23. Log.d("FeedbackProgressScreen 组件卸载时执行");
  24. };
  25. }, []);
  26. return Container(
  27. width: double.infinity,
  28. height: double.infinity,
  29. child: EasyRefresh(
  30. controller: viewModel.refreshController,
  31. onRefresh: viewModel.onRefresh,
  32. onLoad: viewModel.loadMore,
  33. child: LoadStateLayout(
  34. state: state.loadingState,
  35. errorMessage: state.errorMessage,
  36. errorRetry: () {
  37. viewModel.retryRequest();
  38. },
  39. successSliverWidget: [
  40. SliverList(
  41. delegate: SliverChildBuilderDelegate(
  42. (context, index) {
  43. return FeedbackItem(index: index, item: state.datas[index]).onTap((){
  44. FeedbackDetailPage.startInstance(context: context);
  45. });
  46. },
  47. childCount: state.datas.length,
  48. ))
  49. ],
  50. ),
  51. ).marginOnly(top: 5, bottom: 5),
  52. );
  53. }
  54. }