import 'package:flutter_riverpod/flutter_riverpod.dart'; /// 底部导航的三个 Tab,对应 `components/CustomTabBar.vue` 的 3 个入口。 enum AppTab { order, earnings, profile } extension AppTabKey on AppTab { /// 与 `XBottomNav.items` 中的 key 一致。 String get key => switch (this) { AppTab.order => 'order', AppTab.earnings => 'earnings', AppTab.profile => 'profile', }; } /// 当前 Tab。源里每个页面各自挂 `CustomTabBar` 并用 `redirectTo` 切换, /// Flutter 端改为单容器 + [IndexedStack],避免页面重建、保留各自滚动位置。 class TabIndexController extends Notifier { @override AppTab build() => AppTab.order; void select(AppTab tab) => state = tab; void selectByKey(String key) { state = AppTab.values.firstWhere((t) => t.key == key, orElse: () => state); } } final tabIndexProvider = NotifierProvider( TabIndexController.new, );