fix(ui): 修复主题切换功能,支持明暗主题动态切换
- 替换所有硬编码颜色为动态颜色 - 所有页面使用 Theme.of(context) 获取主题颜色 - 支持深色和浅色主题切换 - 修复 GlassPanel 和 NeonGlow 组件的主题适配 - 完善 lightMaterial ColorScheme 定义 - 测试主题切换功能正常 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -37,14 +37,15 @@ class _HomePageState extends State<HomePage> with AutomaticKeepAliveClientMixin
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppColorScheme.darkBackground,
|
||||
backgroundColor: colorScheme.background,
|
||||
body: Consumer<AssetProvider>(
|
||||
builder: (context, provider, _) {
|
||||
return RefreshIndicator(
|
||||
onRefresh: () => provider.refreshAll(force: true),
|
||||
color: AppColorScheme.darkPrimary,
|
||||
color: colorScheme.primary,
|
||||
child: SingleChildScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
padding: const EdgeInsets.fromLTRB(24, 8, 24, 100),
|
||||
@@ -185,6 +186,8 @@ class _HomePageState extends State<HomePage> with AutomaticKeepAliveClientMixin
|
||||
class _GreetingSection extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
|
||||
return Consumer<AuthProvider>(
|
||||
builder: (context, auth, _) {
|
||||
return Column(
|
||||
@@ -193,7 +196,7 @@ class _GreetingSection extends StatelessWidget {
|
||||
Text(
|
||||
'欢迎回来,',
|
||||
style: TextStyle(
|
||||
color: AppColorScheme.darkOnSurfaceVariant,
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
fontSize: 14,
|
||||
letterSpacing: 0.5,
|
||||
),
|
||||
@@ -201,8 +204,8 @@ class _GreetingSection extends StatelessWidget {
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'${auth.user?.username ?? '用户'}',
|
||||
style: const TextStyle(
|
||||
color: AppColorScheme.darkOnSurface,
|
||||
style: TextStyle(
|
||||
color: colorScheme.onSurface,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 24,
|
||||
),
|
||||
@@ -222,14 +225,17 @@ class _GlassBalanceCard extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(32),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColorScheme.darkSurfaceBright.withValues(alpha: 0.4),
|
||||
color: colorScheme.surfaceBright.withOpacity(isDark ? 0.4 : 0.6),
|
||||
borderRadius: BorderRadius.circular(32),
|
||||
border: Border.all(
|
||||
color: AppColorScheme.darkOutlineVariant.withValues(alpha: 0.1),
|
||||
color: colorScheme.outlineVariant.withOpacity(0.1),
|
||||
),
|
||||
),
|
||||
child: Stack(
|
||||
@@ -243,7 +249,7 @@ class _GlassBalanceCard extends StatelessWidget {
|
||||
height: 128,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: AppColorScheme.darkPrimary.withValues(alpha: 0.2),
|
||||
color: colorScheme.primary.withOpacity(isDark ? 0.2 : 0.1),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -256,7 +262,7 @@ class _GlassBalanceCard extends StatelessWidget {
|
||||
height: 128,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: AppColorScheme.darkSecondary.withValues(alpha: 0.1),
|
||||
color: colorScheme.secondary.withOpacity(isDark ? 0.1 : 0.05),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -270,7 +276,7 @@ class _GlassBalanceCard extends StatelessWidget {
|
||||
Text(
|
||||
'总资产',
|
||||
style: TextStyle(
|
||||
color: AppColorScheme.darkOnSurfaceVariant,
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
fontSize: 11,
|
||||
letterSpacing: 2,
|
||||
fontWeight: FontWeight.w500,
|
||||
@@ -279,7 +285,7 @@ class _GlassBalanceCard extends StatelessWidget {
|
||||
const SizedBox(width: 8),
|
||||
Icon(
|
||||
LucideIcons.eye,
|
||||
color: AppColorScheme.darkOnSurfaceVariant,
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
size: 14,
|
||||
),
|
||||
],
|
||||
@@ -291,8 +297,8 @@ class _GlassBalanceCard extends StatelessWidget {
|
||||
children: [
|
||||
Text(
|
||||
overview?.totalAsset ?? '0.00',
|
||||
style: const TextStyle(
|
||||
color: AppColorScheme.darkOnSurface,
|
||||
style: TextStyle(
|
||||
color: colorScheme.onSurface,
|
||||
fontWeight: FontWeight.w900,
|
||||
fontSize: 48,
|
||||
letterSpacing: -2,
|
||||
@@ -304,7 +310,7 @@ class _GlassBalanceCard extends StatelessWidget {
|
||||
child: Text(
|
||||
'USDT',
|
||||
style: TextStyle(
|
||||
color: AppColorScheme.darkPrimary,
|
||||
color: colorScheme.primary,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 20,
|
||||
),
|
||||
@@ -317,7 +323,7 @@ class _GlassBalanceCard extends StatelessWidget {
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColorScheme.up.withValues(alpha: 0.1),
|
||||
color: AppColorScheme.up.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Row(
|
||||
@@ -341,7 +347,7 @@ class _GlassBalanceCard extends StatelessWidget {
|
||||
Text(
|
||||
"Today's PNL",
|
||||
style: TextStyle(
|
||||
color: AppColorScheme.darkOnSurfaceVariant,
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
@@ -370,19 +376,21 @@ class _QuickActionsGrid extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
_QuickActionBtn(
|
||||
icon: LucideIcons.plus,
|
||||
label: '充值',
|
||||
color: AppColorScheme.darkPrimary,
|
||||
color: colorScheme.primary,
|
||||
onTap: onDeposit,
|
||||
),
|
||||
_QuickActionBtn(
|
||||
icon: LucideIcons.wallet,
|
||||
label: '提现',
|
||||
color: AppColorScheme.darkSecondary,
|
||||
color: colorScheme.secondary,
|
||||
onTap: onWithdraw,
|
||||
),
|
||||
_QuickActionBtn(
|
||||
@@ -394,7 +402,7 @@ class _QuickActionsGrid extends StatelessWidget {
|
||||
_QuickActionBtn(
|
||||
icon: LucideIcons.trendingUp,
|
||||
label: '交易',
|
||||
color: AppColorScheme.darkPrimary,
|
||||
color: colorScheme.primary,
|
||||
onTap: () {
|
||||
// TODO: 实现跳转到交易页面的功能
|
||||
},
|
||||
@@ -427,6 +435,8 @@ class _QuickActionBtnState extends State<_QuickActionBtn> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
|
||||
return GestureDetector(
|
||||
onTap: widget.onTap,
|
||||
onTapDown: (_) => setState(() => _isPressed = true),
|
||||
@@ -440,14 +450,14 @@ class _QuickActionBtnState extends State<_QuickActionBtn> {
|
||||
height: 56,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: AppColorScheme.darkSurfaceHigh,
|
||||
color: colorScheme.surfaceContainerHigh,
|
||||
border: Border.all(
|
||||
color: widget.color.withValues(alpha: 0.2),
|
||||
color: widget.color.withOpacity(0.2),
|
||||
),
|
||||
boxShadow: _isPressed
|
||||
? [
|
||||
BoxShadow(
|
||||
color: widget.color.withValues(alpha: 0.4),
|
||||
color: widget.color.withOpacity(0.4),
|
||||
blurRadius: 20,
|
||||
spreadRadius: 0,
|
||||
),
|
||||
@@ -464,7 +474,7 @@ class _QuickActionBtnState extends State<_QuickActionBtn> {
|
||||
Text(
|
||||
widget.label,
|
||||
style: TextStyle(
|
||||
color: AppColorScheme.darkOnSurfaceVariant,
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
@@ -483,16 +493,18 @@ class _HoldingsSection extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
// 标题行
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text(
|
||||
Text(
|
||||
'我的持仓',
|
||||
style: TextStyle(
|
||||
color: AppColorScheme.darkOnSurface,
|
||||
color: colorScheme.onSurface,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 18,
|
||||
letterSpacing: -0.5,
|
||||
@@ -501,12 +513,12 @@ class _HoldingsSection extends StatelessWidget {
|
||||
TextButton(
|
||||
onPressed: () {},
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: AppColorScheme.darkPrimary,
|
||||
foregroundColor: colorScheme.primary,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Text(
|
||||
Text(
|
||||
'资产详情',
|
||||
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 14),
|
||||
),
|
||||
@@ -514,7 +526,7 @@ class _HoldingsSection extends StatelessWidget {
|
||||
Icon(
|
||||
LucideIcons.chevronRight,
|
||||
size: 16,
|
||||
color: AppColorScheme.darkPrimary,
|
||||
color: colorScheme.primary,
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -535,14 +547,17 @@ class _EmptyHoldings extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(vertical: 48, horizontal: 24),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColorScheme.darkSurfaceLow.withValues(alpha: 0.5),
|
||||
color: colorScheme.surfaceContainerLow.withOpacity(0.5),
|
||||
borderRadius: BorderRadius.circular(40),
|
||||
border: Border.all(
|
||||
color: AppColorScheme.darkOutlineVariant.withValues(alpha: 0.1),
|
||||
color: colorScheme.outlineVariant.withOpacity(0.1),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
@@ -562,8 +577,8 @@ class _EmptyHoldings extends StatelessWidget {
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
gradient: LinearGradient(
|
||||
colors: [
|
||||
AppColorScheme.darkPrimary.withValues(alpha: 0.2),
|
||||
AppColorScheme.darkSecondary.withValues(alpha: 0.2),
|
||||
colorScheme.primary.withOpacity(isDark ? 0.2 : 0.1),
|
||||
colorScheme.secondary.withOpacity(isDark ? 0.2 : 0.1),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -577,14 +592,14 @@ class _EmptyHoldings extends StatelessWidget {
|
||||
width: 80,
|
||||
height: 80,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColorScheme.darkSurfaceHighest,
|
||||
color: colorScheme.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
border: Border.all(
|
||||
color: AppColorScheme.darkOutlineVariant.withValues(alpha: 0.2),
|
||||
color: colorScheme.outlineVariant.withOpacity(0.2),
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withValues(alpha: 0.3),
|
||||
color: Colors.black.withOpacity(isDark ? 0.3 : 0.1),
|
||||
blurRadius: 24,
|
||||
offset: const Offset(0, 8),
|
||||
),
|
||||
@@ -592,7 +607,7 @@ class _EmptyHoldings extends StatelessWidget {
|
||||
),
|
||||
child: Icon(
|
||||
LucideIcons.wallet,
|
||||
color: AppColorScheme.darkPrimary,
|
||||
color: colorScheme.primary,
|
||||
size: 40,
|
||||
),
|
||||
),
|
||||
@@ -607,9 +622,9 @@ class _EmptyHoldings extends StatelessWidget {
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: AppColorScheme.up.withValues(alpha: 0.2),
|
||||
color: AppColorScheme.up.withOpacity(0.2),
|
||||
border: Border.all(
|
||||
color: AppColorScheme.up.withValues(alpha: 0.3),
|
||||
color: AppColorScheme.up.withOpacity(0.3),
|
||||
),
|
||||
),
|
||||
child: Icon(
|
||||
@@ -623,10 +638,10 @@ class _EmptyHoldings extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
const Text(
|
||||
Text(
|
||||
'No holdings yet.',
|
||||
style: TextStyle(
|
||||
color: AppColorScheme.darkOnSurface,
|
||||
color: colorScheme.onSurface,
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 16,
|
||||
),
|
||||
@@ -635,7 +650,7 @@ class _EmptyHoldings extends StatelessWidget {
|
||||
Text(
|
||||
'暂无持仓,快去交易吧~',
|
||||
style: TextStyle(
|
||||
color: AppColorScheme.darkOnSurfaceVariant,
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
@@ -643,11 +658,11 @@ class _EmptyHoldings extends StatelessWidget {
|
||||
// 开始交易按钮
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: AppColorScheme.darkCtaGradient,
|
||||
gradient: isDark ? AppColorScheme.darkCtaGradient : AppColorScheme.lightCtaGradient,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColorScheme.darkPrimary.withValues(alpha: 0.3),
|
||||
color: colorScheme.primary.withOpacity(isDark ? 0.3 : 0.2),
|
||||
blurRadius: 30,
|
||||
offset: const Offset(0, 10),
|
||||
),
|
||||
@@ -658,12 +673,12 @@ class _EmptyHoldings extends StatelessWidget {
|
||||
child: InkWell(
|
||||
onTap: () {},
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 40, vertical: 16),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 40, vertical: 16),
|
||||
child: Text(
|
||||
'Start Trading',
|
||||
style: TextStyle(
|
||||
color: AppColorScheme.darkBackground,
|
||||
color: isDark ? colorScheme.background : const Color(0xFFFFFFFF),
|
||||
fontWeight: FontWeight.w900,
|
||||
fontSize: 16,
|
||||
letterSpacing: -0.5,
|
||||
@@ -687,14 +702,15 @@ class _HoldingsList extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
final displayHoldings = holdings.length > 5 ? holdings.sublist(0, 5) : holdings;
|
||||
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: AppColorScheme.darkSurface.withValues(alpha: 0.5),
|
||||
color: colorScheme.surface.withOpacity(0.5),
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
border: Border.all(
|
||||
color: AppColorScheme.darkOutlineVariant.withValues(alpha: 0.1),
|
||||
color: colorScheme.outlineVariant.withOpacity(0.1),
|
||||
),
|
||||
),
|
||||
child: ListView.separated(
|
||||
@@ -703,7 +719,7 @@ class _HoldingsList extends StatelessWidget {
|
||||
padding: const EdgeInsets.all(16),
|
||||
itemCount: displayHoldings.length,
|
||||
separatorBuilder: (_, __) => Divider(
|
||||
color: AppColorScheme.darkOutlineVariant.withValues(alpha: 0.1),
|
||||
color: colorScheme.outlineVariant.withOpacity(0.1),
|
||||
height: 1,
|
||||
),
|
||||
itemBuilder: (context, index) {
|
||||
@@ -724,6 +740,8 @@ class _HoldingItem extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
child: Row(
|
||||
@@ -733,11 +751,11 @@ class _HoldingItem extends StatelessWidget {
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 18,
|
||||
backgroundColor: AppColorScheme.darkPrimary.withValues(alpha: 0.1),
|
||||
backgroundColor: colorScheme.primary.withOpacity(0.1),
|
||||
child: Text(
|
||||
holding.coinCode.substring(0, 1),
|
||||
style: const TextStyle(
|
||||
color: AppColorScheme.darkPrimary,
|
||||
style: TextStyle(
|
||||
color: colorScheme.primary,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
@@ -748,8 +766,8 @@ class _HoldingItem extends StatelessWidget {
|
||||
children: [
|
||||
Text(
|
||||
holding.coinCode,
|
||||
style: const TextStyle(
|
||||
color: AppColorScheme.darkOnSurface,
|
||||
style: TextStyle(
|
||||
color: colorScheme.onSurface,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16,
|
||||
),
|
||||
@@ -757,7 +775,7 @@ class _HoldingItem extends StatelessWidget {
|
||||
Text(
|
||||
holding.quantity,
|
||||
style: TextStyle(
|
||||
color: AppColorScheme.darkOnSurfaceVariant,
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
@@ -770,8 +788,8 @@ class _HoldingItem extends StatelessWidget {
|
||||
children: [
|
||||
Text(
|
||||
'${holding.currentValue} USDT',
|
||||
style: const TextStyle(
|
||||
color: AppColorScheme.darkOnSurface,
|
||||
style: TextStyle(
|
||||
color: colorScheme.onSurface,
|
||||
fontWeight: FontWeight.w500,
|
||||
fontSize: 14,
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user