251 lines
7.6 KiB
Dart
251 lines
7.6 KiB
Dart
import 'package:flutter/material.dart';
|
||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||
import 'package:go_router/go_router.dart';
|
||
|
||
import '../features/auth/presentation/pages/splash_page.dart';
|
||
import '../features/auth/presentation/pages/guide_page.dart';
|
||
import '../features/auth/presentation/pages/onboarding_page.dart';
|
||
import '../features/auth/presentation/pages/backup_mnemonic_page.dart';
|
||
import '../features/auth/presentation/pages/verify_mnemonic_page.dart';
|
||
import '../features/auth/presentation/pages/wallet_created_page.dart';
|
||
import '../features/home/presentation/pages/home_shell_page.dart';
|
||
import '../features/ranking/presentation/pages/ranking_page.dart';
|
||
import '../features/mining/presentation/pages/mining_page.dart';
|
||
import '../features/trading/presentation/pages/trading_page.dart';
|
||
import '../features/profile/presentation/pages/profile_page.dart';
|
||
import '../features/profile/presentation/pages/edit_profile_page.dart';
|
||
import '../features/share/presentation/pages/share_page.dart';
|
||
import '../features/deposit/presentation/pages/deposit_usdt_page.dart';
|
||
import '../features/planting/presentation/pages/planting_quantity_page.dart';
|
||
import '../features/planting/presentation/pages/planting_location_page.dart';
|
||
import 'route_paths.dart';
|
||
import 'route_names.dart';
|
||
|
||
final _rootNavigatorKey = GlobalKey<NavigatorState>();
|
||
final _shellNavigatorKey = GlobalKey<NavigatorState>();
|
||
|
||
/// 备份助记词页面参数
|
||
class BackupMnemonicParams {
|
||
final List<String> mnemonicWords;
|
||
final String kavaAddress;
|
||
final String dstAddress;
|
||
final String bscAddress;
|
||
final String serialNumber;
|
||
final String? referralCode; // 推荐码
|
||
final String? publicKey; // MPC 公钥
|
||
final bool isMpcMode; // 是否为 MPC 模式
|
||
|
||
BackupMnemonicParams({
|
||
required this.mnemonicWords,
|
||
required this.kavaAddress,
|
||
required this.dstAddress,
|
||
required this.bscAddress,
|
||
required this.serialNumber,
|
||
this.referralCode,
|
||
this.publicKey,
|
||
this.isMpcMode = false,
|
||
});
|
||
}
|
||
|
||
/// 确认备份页面参数(复用 BackupMnemonicParams)
|
||
typedef VerifyMnemonicParams = BackupMnemonicParams;
|
||
|
||
/// 创建成功页面参数
|
||
class WalletCreatedParams {
|
||
final String kavaAddress;
|
||
final String dstAddress;
|
||
final String bscAddress;
|
||
final String serialNumber;
|
||
final String? referralCode;
|
||
|
||
WalletCreatedParams({
|
||
required this.kavaAddress,
|
||
required this.dstAddress,
|
||
required this.bscAddress,
|
||
required this.serialNumber,
|
||
this.referralCode,
|
||
});
|
||
}
|
||
|
||
/// 分享页面参数
|
||
class SharePageParams {
|
||
final String shareLink;
|
||
final String? referralCode;
|
||
|
||
SharePageParams({
|
||
required this.shareLink,
|
||
this.referralCode,
|
||
});
|
||
}
|
||
|
||
final appRouterProvider = Provider<GoRouter>((ref) {
|
||
return GoRouter(
|
||
navigatorKey: _rootNavigatorKey,
|
||
initialLocation: RoutePaths.splash,
|
||
debugLogDiagnostics: true,
|
||
routes: [
|
||
// Splash Screen
|
||
GoRoute(
|
||
path: RoutePaths.splash,
|
||
name: RouteNames.splash,
|
||
builder: (context, state) => const SplashPage(),
|
||
),
|
||
|
||
// Guide Pages (向导页)
|
||
GoRoute(
|
||
path: RoutePaths.guide,
|
||
name: RouteNames.guide,
|
||
builder: (context, state) => const GuidePage(),
|
||
),
|
||
|
||
// Onboarding / Create Account
|
||
GoRoute(
|
||
path: RoutePaths.onboarding,
|
||
name: RouteNames.onboarding,
|
||
builder: (context, state) => const OnboardingPage(),
|
||
),
|
||
|
||
// Backup Mnemonic
|
||
GoRoute(
|
||
path: RoutePaths.backupMnemonic,
|
||
name: RouteNames.backupMnemonic,
|
||
builder: (context, state) {
|
||
final params = state.extra as BackupMnemonicParams;
|
||
return BackupMnemonicPage(
|
||
mnemonicWords: params.mnemonicWords,
|
||
kavaAddress: params.kavaAddress,
|
||
dstAddress: params.dstAddress,
|
||
bscAddress: params.bscAddress,
|
||
serialNumber: params.serialNumber,
|
||
referralCode: params.referralCode,
|
||
publicKey: params.publicKey,
|
||
isMpcMode: params.isMpcMode,
|
||
);
|
||
},
|
||
),
|
||
|
||
// Verify Mnemonic (确认备份)
|
||
GoRoute(
|
||
path: RoutePaths.verifyMnemonic,
|
||
name: RouteNames.verifyMnemonic,
|
||
builder: (context, state) {
|
||
final params = state.extra as VerifyMnemonicParams;
|
||
return VerifyMnemonicPage(
|
||
mnemonicWords: params.mnemonicWords,
|
||
kavaAddress: params.kavaAddress,
|
||
dstAddress: params.dstAddress,
|
||
bscAddress: params.bscAddress,
|
||
serialNumber: params.serialNumber,
|
||
);
|
||
},
|
||
),
|
||
|
||
// Wallet Created (创建成功)
|
||
GoRoute(
|
||
path: RoutePaths.walletCreated,
|
||
name: RouteNames.walletCreated,
|
||
builder: (context, state) {
|
||
final params = state.extra as WalletCreatedParams;
|
||
return WalletCreatedPage(
|
||
kavaAddress: params.kavaAddress,
|
||
dstAddress: params.dstAddress,
|
||
bscAddress: params.bscAddress,
|
||
serialNumber: params.serialNumber,
|
||
referralCode: params.referralCode,
|
||
);
|
||
},
|
||
),
|
||
|
||
// Edit Profile (编辑资料)
|
||
GoRoute(
|
||
path: RoutePaths.editProfile,
|
||
name: RouteNames.editProfile,
|
||
builder: (context, state) => const EditProfilePage(),
|
||
),
|
||
|
||
// Share Page (分享页面)
|
||
GoRoute(
|
||
path: RoutePaths.share,
|
||
name: RouteNames.share,
|
||
builder: (context, state) {
|
||
final params = state.extra as SharePageParams;
|
||
return SharePage(
|
||
shareLink: params.shareLink,
|
||
referralCode: params.referralCode,
|
||
);
|
||
},
|
||
),
|
||
|
||
// Deposit USDT Page (充值 USDT)
|
||
GoRoute(
|
||
path: RoutePaths.depositUsdt,
|
||
name: RouteNames.depositUsdt,
|
||
builder: (context, state) => const DepositUsdtPage(),
|
||
),
|
||
|
||
// Planting Quantity Page (认种 - 选择数量)
|
||
GoRoute(
|
||
path: RoutePaths.plantingQuantity,
|
||
name: RouteNames.plantingQuantity,
|
||
builder: (context, state) => const PlantingQuantityPage(),
|
||
),
|
||
|
||
// Planting Location Page (认种 - 选择省市)
|
||
GoRoute(
|
||
path: RoutePaths.plantingLocation,
|
||
name: RouteNames.plantingLocation,
|
||
builder: (context, state) {
|
||
final params = state.extra as PlantingLocationParams;
|
||
return PlantingLocationPage(
|
||
quantity: params.quantity,
|
||
totalPrice: params.totalPrice,
|
||
);
|
||
},
|
||
),
|
||
|
||
// Main Shell with Bottom Navigation
|
||
ShellRoute(
|
||
navigatorKey: _shellNavigatorKey,
|
||
builder: (context, state, child) => HomeShellPage(child: child),
|
||
routes: [
|
||
// Ranking Tab
|
||
GoRoute(
|
||
path: RoutePaths.ranking,
|
||
name: RouteNames.ranking,
|
||
pageBuilder: (context, state) => const NoTransitionPage(
|
||
child: RankingPage(),
|
||
),
|
||
),
|
||
|
||
// Mining Tab
|
||
GoRoute(
|
||
path: RoutePaths.mining,
|
||
name: RouteNames.mining,
|
||
pageBuilder: (context, state) => const NoTransitionPage(
|
||
child: MiningPage(),
|
||
),
|
||
),
|
||
|
||
// Trading Tab
|
||
GoRoute(
|
||
path: RoutePaths.trading,
|
||
name: RouteNames.trading,
|
||
pageBuilder: (context, state) => const NoTransitionPage(
|
||
child: TradingPage(),
|
||
),
|
||
),
|
||
|
||
// Profile Tab
|
||
GoRoute(
|
||
path: RoutePaths.profile,
|
||
name: RouteNames.profile,
|
||
pageBuilder: (context, state) => const NoTransitionPage(
|
||
child: ProfilePage(),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
],
|
||
);
|
||
});
|