feat: 完成 Flutter 版智能电网 IoT 管理应用初始化搭建
This commit is contained in:
commit
f61b7bf90b
120 files changed
+15229
No files matched your search
@@ -0,0 +1,31 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
/// 底部导航的四个 Tab,对应 `components/XBottomNav.vue` 的 4 个入口。
|
||||
enum AppTab { workbench, customer, project, mine }
|
||||
|
||||
extension AppTabKey on AppTab {
|
||||
/// 与 `XBottomNav.items` 中的 key 一致。
|
||||
String get key => switch (this) {
|
||||
AppTab.workbench => 'workbench',
|
||||
AppTab.customer => 'customer',
|
||||
AppTab.project => 'project',
|
||||
AppTab.mine => 'mine',
|
||||
};
|
||||
}
|
||||
|
||||
/// 当前 Tab。对应 uni-app 版 `utils/tabs.ts` 的 `currentTab` ref + `switchTab`。
|
||||
class TabIndexController extends Notifier<AppTab> {
|
||||
@override
|
||||
AppTab build() => AppTab.workbench;
|
||||
|
||||
void select(AppTab tab) => state = tab;
|
||||
|
||||
/// 按 `XBottomNav` 回传的字符串 key 切换。
|
||||
void selectByKey(String key) {
|
||||
state = AppTab.values.firstWhere((t) => t.key == key, orElse: () => state);
|
||||
}
|
||||
}
|
||||
|
||||
final tabIndexProvider = NotifierProvider<TabIndexController, AppTab>(
|
||||
TabIndexController.new,
|
||||
);
|
||||
Reference in new issue
Block a user