import 'package:cpt_community/components/custom_tabs_state.dart'; import 'package:cs_resources/generated/assets.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:plugin_platform/engine/toast/toast_engine.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; import 'package:shared/utils/log_utils.dart'; part 'custom_tabs_vm.g.dart'; @riverpod class CustomTabsVm extends _$CustomTabsVm { CustomTabsState initState(List tabsList, int activeIndex, tabItemBuilder, onClickAction) { CustomTabsState state = CustomTabsState( tabsList: tabsList ?? [], activeIndex: activeIndex ?? 0, tabItemBuilder:tabItemBuilder, onClickAction: onClickAction ); return state; } @override CustomTabsState build(){ CustomTabsState state = initState([], 0, null, null); return state; } Future initPropData(tabsList, activeIndex,tabItemBuilder, onClickAction) async { CustomTabsState newState = state.copyWith( tabsList: tabsList, activeIndex: activeIndex, tabItemBuilder: tabItemBuilder, onClickAction: onClickAction ); state = newState; } // 点击tab void handlerClickTab(int index, item){ CustomTabsState newState = state.copyWith( activeIndex: index ); state = newState; print("切换后新的 sate, ${state.activeIndex}"); // ref.invalidate(customTabsVmProvider); } }