custom_tabs_vm.dart 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import 'package:cpt_community/components/custom_tabs_state.dart';
  2. import 'package:cs_resources/generated/assets.dart';
  3. import 'package:flutter/cupertino.dart';
  4. import 'package:flutter_riverpod/flutter_riverpod.dart';
  5. import 'package:plugin_platform/engine/toast/toast_engine.dart';
  6. import 'package:riverpod_annotation/riverpod_annotation.dart';
  7. import 'package:shared/utils/log_utils.dart';
  8. part 'custom_tabs_vm.g.dart';
  9. @riverpod
  10. class CustomTabsVm extends _$CustomTabsVm {
  11. CustomTabsState initState(List tabsList, int activeIndex, tabItemBuilder, onClickAction) {
  12. CustomTabsState state = CustomTabsState(
  13. tabsList: tabsList ?? [],
  14. activeIndex: activeIndex ?? 0,
  15. tabItemBuilder:tabItemBuilder,
  16. onClickAction: onClickAction
  17. );
  18. return state;
  19. }
  20. @override
  21. CustomTabsState build(){
  22. CustomTabsState state = initState([], 0, null, null);
  23. return state;
  24. }
  25. Future<void> initPropData(tabsList, activeIndex,tabItemBuilder, onClickAction) async {
  26. CustomTabsState newState = state.copyWith(
  27. tabsList: tabsList,
  28. activeIndex: activeIndex,
  29. tabItemBuilder: tabItemBuilder,
  30. onClickAction: onClickAction
  31. );
  32. state = newState;
  33. }
  34. // 点击tab
  35. void handlerClickTab(int index, item){
  36. CustomTabsState newState = state.copyWith(
  37. activeIndex: index
  38. );
  39. state = newState;
  40. print("切换后新的 sate, ${state.activeIndex}");
  41. // ref.invalidate(customTabsVmProvider);
  42. }
  43. }