choose_card_page.dart 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import 'package:cs_resources/generated/l10n.dart';
  2. import 'package:cs_resources/theme/app_colors_theme.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:auto_route/auto_route.dart';
  5. import 'package:flutter_hooks/flutter_hooks.dart';
  6. import 'package:hooks_riverpod/hooks_riverpod.dart';
  7. import 'package:router/ext/auto_router_extensions.dart';
  8. import 'package:widgets/ext/ex_widget.dart';
  9. import 'package:widgets/load_state_layout.dart';
  10. import 'package:widgets/my_appbar.dart';
  11. import 'package:widgets/my_button.dart';
  12. import 'package:widgets/my_text_view.dart';
  13. import 'package:widgets/widget_export.dart';
  14. import '../../router/page/payment_page_router.dart';
  15. import '../payment/manage/item_manage.dart';
  16. import 'choose_card_view_model.dart';
  17. @RoutePage()
  18. class ChooseCardPage extends HookConsumerWidget {
  19. const ChooseCardPage({Key? key}) : super(key: key);
  20. //启动当前页面
  21. static void startInstance({BuildContext? context}) {
  22. if (context != null) {
  23. context.router.push(const ChooseCardPageRoute());
  24. } else {
  25. appRouter.push(const ChooseCardPageRoute());
  26. }
  27. }
  28. @override
  29. Widget build(BuildContext context, WidgetRef ref) {
  30. final viewModel = ref.watch(chooseCardViewModelProvider.notifier);
  31. final state = ref.watch(chooseCardViewModelProvider);
  32. useEffect(() {
  33. // 组件挂载时执行 - 执行接口请求
  34. Future.microtask(() => viewModel.fetchList());
  35. return () {
  36. // 组件卸载时执行
  37. };
  38. }, []);
  39. return Scaffold(
  40. appBar: MyAppBar.appBar(
  41. context,
  42. S.current.payment,
  43. backgroundColor: context.appColors.whiteBG,
  44. ),
  45. backgroundColor: context.appColors.backgroundDark,
  46. body: SizedBox(
  47. width: double.infinity,
  48. height: double.infinity,
  49. child: Column(
  50. children: [
  51. EasyRefresh(
  52. controller: viewModel.refreshController,
  53. onRefresh: viewModel.onRefresh,
  54. onLoad: viewModel.loadMore,
  55. child: LoadStateLayout(
  56. state: state.loadingState,
  57. errorMessage: state.errorMessage,
  58. errorRetry: () {
  59. viewModel.retryRequest();
  60. },
  61. successSliverWidget: [
  62. //添加新卡
  63. SliverToBoxAdapter(
  64. child: MyTextView(
  65. S.current.add_new_card,
  66. fontSize: 16,
  67. textAlign: TextAlign.center,
  68. marginLeft: 22.5,
  69. marginTop: 14,
  70. marginBottom: 15,
  71. marginRight: 22.5,
  72. cornerRadius: 5,
  73. paddingTop: 12,
  74. paddingBottom: 12,
  75. onClick: viewModel.gotoAddCardPage,
  76. borderWidth: 1,
  77. borderColor: context.appColors.textPrimary,
  78. isFontMedium: true,
  79. textColor: context.appColors.textPrimary,
  80. ),
  81. ),
  82. //列表
  83. SliverList(
  84. delegate: SliverChildBuilderDelegate(
  85. (context, index) {
  86. return ManageItem(
  87. index: index,
  88. item: state.datas[index],
  89. deleteAction: () {
  90. viewModel.showDeleteDialog(index);
  91. },
  92. ).onTap(() {
  93. viewModel.setAsPrimary(index);
  94. });
  95. },
  96. childCount: state.datas.length,
  97. ))
  98. ],
  99. ),
  100. ).marginOnly(top: 5, bottom: 5).expanded(),
  101. //底部按钮(其实就是返回)
  102. MyButton(
  103. onPressed: () {
  104. context.appRouter.maybePop();
  105. },
  106. text: S.current.next,
  107. textColor: Colors.white,
  108. backgroundColor: context.appColors.btnBgDefault,
  109. fontWeight: FontWeight.w500,
  110. type: ClickType.throttle,
  111. fontSize: 16,
  112. minHeight: 50,
  113. radius: 0,
  114. ),
  115. ],
  116. ),
  117. ),
  118. );
  119. }
  120. }