custom_tabs_vm.dart 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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:plugin_platform/engine/toast/toast_engine.dart';
  5. import 'package:riverpod_annotation/riverpod_annotation.dart';
  6. import 'package:shared/utils/log_utils.dart';
  7. part 'custom_tabs_vm.g.dart';
  8. @riverpod
  9. class CustomTabsVm extends _$CustomTabsVm {
  10. CustomTabsState initState(tabsList, activeIndex,tabItemBuilder, onClickAction) {
  11. CustomTabsState state = CustomTabsState(
  12. tabsList: tabsList,
  13. activeIndex:activeIndex,
  14. tabItemBuilder: tabItemBuilder,
  15. onClickAction: onClickAction
  16. );
  17. return state;
  18. }
  19. @override
  20. CustomTabsState build(){
  21. CustomTabsState state = initState([],0,null,null);
  22. return state;
  23. }
  24. Future<void> initPropData(tabsList, activeIndex,tabItemBuilder, onClickAction) async {
  25. CustomTabsState newState = state.copyWith(
  26. tabsList: tabsList,
  27. activeIndex: activeIndex,
  28. tabItemBuilder: tabItemBuilder,
  29. onClickAction: onClickAction
  30. );
  31. state = newState;
  32. }
  33. // 点击tab
  34. void handlerClickTab(int index, item){
  35. CustomTabsState newState = state.copyWith(
  36. activeIndex: index
  37. );
  38. state = newState;
  39. print("切换后新的 sate, ${state.activeIndex}");
  40. }
  41. }