manage_screen.dart 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import 'package:auto_route/auto_route.dart';
  2. import 'package:cs_resources/generated/l10n.dart';
  3. import 'package:cs_resources/theme/app_colors_theme.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:flutter_hooks/flutter_hooks.dart';
  6. import 'package:hooks_riverpod/hooks_riverpod.dart';
  7. import 'package:shared/utils/log_utils.dart';
  8. import 'package:widgets/ext/ex_widget.dart';
  9. import 'package:widgets/load_state_layout.dart';
  10. import 'package:widgets/my_text_view.dart';
  11. import 'package:widgets/widget_export.dart';
  12. import 'item_manage.dart';
  13. import 'manage_view_model.dart';
  14. @RoutePage()
  15. class ManageScreen extends HookConsumerWidget {
  16. @override
  17. Widget build(BuildContext context, WidgetRef ref) {
  18. final viewModel = ref.read(manageViewModelProvider.notifier);
  19. final state = ref.watch(manageViewModelProvider);
  20. useEffect(() {
  21. // 组件挂载时执行 - 执行接口请求
  22. Future.microtask(() => viewModel.fetchList());
  23. return () {
  24. // 组件卸载时执行
  25. };
  26. }, []);
  27. return SizedBox(
  28. width: double.infinity,
  29. height: double.infinity,
  30. child: EasyRefresh(
  31. controller: viewModel.refreshController,
  32. onRefresh: viewModel.onRefresh,
  33. onLoad: viewModel.loadMore,
  34. child: LoadStateLayout(
  35. state: state.loadingState,
  36. errorMessage: state.errorMessage,
  37. errorRetry: () {
  38. viewModel.retryRequest();
  39. },
  40. successSliverWidget: [
  41. //添加新卡
  42. SliverToBoxAdapter(
  43. child: MyTextView(
  44. S.current.add_new_card,
  45. fontSize: 16,
  46. textAlign: TextAlign.center,
  47. marginLeft: 22.5,
  48. marginTop: 14,
  49. marginBottom: 15,
  50. marginRight: 22.5,
  51. cornerRadius: 5,
  52. paddingTop: 12,
  53. paddingBottom: 12,
  54. onClick: viewModel.gotoAddCardPage,
  55. borderWidth: 1,
  56. borderColor: context.appColors.textPrimary,
  57. isFontMedium: true,
  58. textColor: context.appColors.textPrimary,
  59. ),
  60. ),
  61. //列表
  62. SliverList(
  63. delegate: SliverChildBuilderDelegate(
  64. (context, index) {
  65. return ManageItem(
  66. index: index,
  67. item: state.datas[index],
  68. deleteAction: () {
  69. viewModel.showDeleteDialog(index);
  70. },
  71. ).onTap(() {
  72. viewModel.setAsPrimary(index);
  73. });
  74. },
  75. childCount: state.datas.length,
  76. ))
  77. ],
  78. ),
  79. ).marginOnly(top: 5, bottom: 5),
  80. );
  81. }
  82. }