2026-03-22 00:21:21 +08:00
|
|
|
import 'package:flutter/material.dart';
|
2026-03-22 04:50:19 +08:00
|
|
|
import 'package:shadcn_ui/shadcn_ui.dart';
|
2026-03-22 00:21:21 +08:00
|
|
|
import '../home/home_page.dart';
|
|
|
|
|
import '../market/market_page.dart';
|
|
|
|
|
import '../trade/trade_page.dart';
|
|
|
|
|
import '../asset/asset_page.dart';
|
|
|
|
|
import '../mine/mine_page.dart';
|
|
|
|
|
|
2026-03-22 04:50:19 +08:00
|
|
|
/// 主页面(使用 shadcn_ui 风格)
|
2026-03-22 00:21:21 +08:00
|
|
|
class MainPage extends StatefulWidget {
|
|
|
|
|
const MainPage({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<MainPage> createState() => _MainPageState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _MainPageState extends State<MainPage> {
|
|
|
|
|
int _currentIndex = 0;
|
|
|
|
|
|
|
|
|
|
final List<Widget> _pages = [
|
|
|
|
|
const HomePage(),
|
|
|
|
|
const MarketPage(),
|
|
|
|
|
const TradePage(),
|
|
|
|
|
const AssetPage(),
|
|
|
|
|
const MinePage(),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
final List<_TabItem> _tabs = [
|
2026-03-22 04:50:19 +08:00
|
|
|
_TabItem('首页', LucideIcons.house, LucideIcons.house),
|
|
|
|
|
_TabItem('行情', LucideIcons.trendingUp, LucideIcons.trendingUp),
|
|
|
|
|
_TabItem('交易', LucideIcons.arrowLeftRight, LucideIcons.arrowLeftRight),
|
|
|
|
|
_TabItem('资产', LucideIcons.wallet, LucideIcons.wallet),
|
|
|
|
|
_TabItem('我的', LucideIcons.user, LucideIcons.user),
|
2026-03-22 00:21:21 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2026-03-22 04:50:19 +08:00
|
|
|
final theme = ShadTheme.of(context);
|
|
|
|
|
|
2026-03-22 00:21:21 +08:00
|
|
|
return Scaffold(
|
|
|
|
|
body: IndexedStack(
|
|
|
|
|
index: _currentIndex,
|
|
|
|
|
children: _pages,
|
|
|
|
|
),
|
2026-03-22 04:50:19 +08:00
|
|
|
bottomNavigationBar: Container(
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: theme.colorScheme.background,
|
|
|
|
|
border: Border(
|
|
|
|
|
top: BorderSide(color: theme.colorScheme.border),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
child: SafeArea(
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 8),
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
|
|
|
children: _tabs.asMap().entries.map((entry) {
|
|
|
|
|
final index = entry.key;
|
|
|
|
|
final tab = entry.value;
|
|
|
|
|
final isSelected = index == _currentIndex;
|
2026-03-22 00:21:21 +08:00
|
|
|
|
2026-03-22 04:50:19 +08:00
|
|
|
return GestureDetector(
|
|
|
|
|
onTap: () => setState(() => _currentIndex = index),
|
|
|
|
|
behavior: HitTestBehavior.opaque,
|
|
|
|
|
child: Container(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
Icon(
|
|
|
|
|
tab.icon,
|
|
|
|
|
color: isSelected
|
|
|
|
|
? theme.colorScheme.primary
|
|
|
|
|
: theme.colorScheme.mutedForeground,
|
|
|
|
|
size: 24,
|
2026-03-22 00:21:21 +08:00
|
|
|
),
|
2026-03-22 04:50:19 +08:00
|
|
|
const SizedBox(height: 4),
|
|
|
|
|
Text(
|
|
|
|
|
tab.label,
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 12,
|
|
|
|
|
color: isSelected
|
|
|
|
|
? theme.colorScheme.primary
|
|
|
|
|
: theme.colorScheme.mutedForeground,
|
|
|
|
|
fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
2026-03-22 00:21:21 +08:00
|
|
|
),
|
2026-03-22 04:50:19 +08:00
|
|
|
);
|
|
|
|
|
}).toList(),
|
|
|
|
|
),
|
2026-03-22 00:21:21 +08:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _TabItem {
|
|
|
|
|
final String label;
|
|
|
|
|
final IconData icon;
|
|
|
|
|
final IconData selectedIcon;
|
|
|
|
|
|
|
|
|
|
_TabItem(this.label, this.icon, this.selectedIcon);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// IndexedStack 用于保持页面状态
|
|
|
|
|
class IndexedStack extends StatefulWidget {
|
|
|
|
|
final int index;
|
|
|
|
|
final List<Widget> children;
|
|
|
|
|
|
|
|
|
|
const IndexedStack({
|
|
|
|
|
super.key,
|
|
|
|
|
required this.index,
|
|
|
|
|
required this.children,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<IndexedStack> createState() => _IndexedStackState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _IndexedStackState extends State<IndexedStack> {
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Stack(
|
|
|
|
|
children: widget.children.asMap().entries.map((entry) {
|
|
|
|
|
return Positioned.fill(
|
|
|
|
|
child: Offstage(
|
|
|
|
|
offstage: entry.key != widget.index,
|
|
|
|
|
child: TickerMode(
|
|
|
|
|
enabled: entry.key == widget.index,
|
|
|
|
|
child: entry.value,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}).toList(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|