创建完整的 Flutter 项目结构,包含 Android 和 iOS 平台配置、核心网络层、路由、状态管理及业务模块(订单、收益、认证),适配原 uni-app 项目功能逻辑
31 lines
962 B
Dart
31 lines
962 B
Dart
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<AppTab> {
|
|
@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, AppTab>(
|
|
TabIndexController.new,
|
|
);
|