111
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:lucide_icons_flutter/lucide_icons.dart';
|
||||
import '../../../core/theme/app_theme.dart';
|
||||
import '../../../core/theme/app_color_scheme.dart';
|
||||
import '../../../core/theme/app_spacing.dart';
|
||||
import '../../../providers/auth_provider.dart';
|
||||
import '../main/main_page.dart';
|
||||
|
||||
/// 首頁頂欄 - Logo + 搜索/通知/頭像
|
||||
/// 首頁頂欄 - Logo + 頭像
|
||||
class HeaderBar extends StatelessWidget {
|
||||
const HeaderBar({super.key});
|
||||
|
||||
@@ -30,37 +29,29 @@ class HeaderBar extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
// Search button
|
||||
_IconButton(
|
||||
icon: LucideIcons.search,
|
||||
colorScheme: colorScheme,
|
||||
onTap: () {},
|
||||
),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
// Bell button
|
||||
_IconButton(
|
||||
icon: LucideIcons.bell,
|
||||
colorScheme: colorScheme,
|
||||
onTap: () {},
|
||||
),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
// Avatar
|
||||
// Avatar — 点击跳转到"我的"页面
|
||||
Consumer<AuthProvider>(
|
||||
builder: (context, auth, _) {
|
||||
final username = auth.user?.username ?? '';
|
||||
final initial = username.isNotEmpty ? username[0].toUpperCase() : '?';
|
||||
return Container(
|
||||
width: 32,
|
||||
height: 32,
|
||||
decoration: BoxDecoration(
|
||||
color: colorScheme.primary,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
initial,
|
||||
style: AppTextStyles.headlineMedium(context).copyWith(
|
||||
color: AppColorScheme.darkOnPrimary,
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
final mainState = context.findAncestorStateOfType<MainPageState>();
|
||||
mainState?.switchToTab(4);
|
||||
},
|
||||
child: Container(
|
||||
width: 32,
|
||||
height: 32,
|
||||
decoration: BoxDecoration(
|
||||
color: colorScheme.primary,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
initial,
|
||||
style: AppTextStyles.headlineMedium(context).copyWith(
|
||||
color: colorScheme.onPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -71,36 +62,3 @@ class HeaderBar extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _IconButton extends StatelessWidget {
|
||||
const _IconButton({
|
||||
required this.icon,
|
||||
required this.colorScheme,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
final IconData icon;
|
||||
final ColorScheme colorScheme;
|
||||
final VoidCallback onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
width: 32,
|
||||
height: 32,
|
||||
decoration: BoxDecoration(
|
||||
color: colorScheme.surfaceContainerHigh,
|
||||
borderRadius: BorderRadius.circular(AppRadius.xl),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Icon(
|
||||
icon,
|
||||
size: 16,
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:lucide_icons_flutter/lucide_icons.dart';
|
||||
import '../../../core/theme/app_theme.dart';
|
||||
@@ -9,8 +10,11 @@ import '../../../core/event/app_event_bus.dart';
|
||||
import '../../../data/models/account_models.dart';
|
||||
import '../../../data/services/bonus_service.dart';
|
||||
import '../../../data/services/asset_service.dart';
|
||||
import '../../../data/services/config_service.dart';
|
||||
import '../../../providers/asset_provider.dart';
|
||||
import '../../../providers/market_provider.dart';
|
||||
import '../../components/glass_panel.dart';
|
||||
import '../main/main_page.dart';
|
||||
import '../mine/welfare_center_page.dart';
|
||||
import '../asset/transfer_page.dart';
|
||||
import '../asset/deposit_page.dart';
|
||||
@@ -33,7 +37,9 @@ class HomePage extends StatefulWidget {
|
||||
class _HomePageState extends State<HomePage>
|
||||
with AutomaticKeepAliveClientMixin {
|
||||
int _totalClaimable = 0;
|
||||
String _customerServiceContact = '';
|
||||
StreamSubscription<AppEvent>? _eventSub;
|
||||
Timer? _refreshTimer;
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
@@ -44,15 +50,28 @@ class _HomePageState extends State<HomePage>
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_loadData();
|
||||
_listenEvents();
|
||||
_startAutoRefresh();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_eventSub?.cancel();
|
||||
_refreshTimer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _startAutoRefresh() {
|
||||
_refreshTimer?.cancel();
|
||||
_refreshTimer = Timer.periodic(const Duration(seconds: 15), (_) {
|
||||
if (!mounted) return;
|
||||
final mainState = context.findAncestorStateOfType<MainPageState>();
|
||||
if (mainState?.isPageVisible(0) != true) return;
|
||||
context.read<AssetProvider>().refreshAll(force: true);
|
||||
context.read<MarketProvider>().loadCoins();
|
||||
});
|
||||
}
|
||||
|
||||
void _listenEvents() {
|
||||
final eventBus = context.read<AppEventBus>();
|
||||
_eventSub = eventBus.on(AppEventType.assetChanged, (_) {
|
||||
@@ -67,7 +86,9 @@ class _HomePageState extends State<HomePage>
|
||||
final provider = context.read<AssetProvider>();
|
||||
provider.loadOverview();
|
||||
provider.loadTradeAccount();
|
||||
context.read<MarketProvider>().loadCoins();
|
||||
_checkBonusStatus();
|
||||
_loadCustomerService();
|
||||
}
|
||||
|
||||
Future<void> _checkBonusStatus() async {
|
||||
@@ -82,6 +103,18 @@ class _HomePageState extends State<HomePage>
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
Future<void> _loadCustomerService() async {
|
||||
try {
|
||||
final configService = context.read<ConfigService>();
|
||||
final response = await configService.getCustomerServiceContact();
|
||||
if (response.success && response.data != null && response.data!.isNotEmpty) {
|
||||
setState(() {
|
||||
_customerServiceContact = response.data!;
|
||||
});
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
@@ -130,6 +163,10 @@ class _HomePageState extends State<HomePage>
|
||||
MaterialPageRoute(builder: (_) => const WelfareCenterPage()),
|
||||
),
|
||||
),
|
||||
if (_customerServiceContact.isNotEmpty) ...[
|
||||
SizedBox(height: AppSpacing.md),
|
||||
_CustomerServiceCard(contact: _customerServiceContact),
|
||||
],
|
||||
SizedBox(height: AppSpacing.lg),
|
||||
// 熱門幣種
|
||||
HotCoinsSection(),
|
||||
@@ -684,3 +721,75 @@ class _ProfitStatCard extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 客服联系卡片
|
||||
class _CustomerServiceCard extends StatelessWidget {
|
||||
final String contact;
|
||||
const _CustomerServiceCard({required this.contact});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
|
||||
return GestureDetector(
|
||||
onLongPress: () {
|
||||
Clipboard.setData(ClipboardData(text: contact));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('已复制客服账号'), duration: Duration(seconds: 2)),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
padding: EdgeInsets.all(AppSpacing.lg),
|
||||
decoration: BoxDecoration(
|
||||
color: colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(AppRadius.xl),
|
||||
border: Border.all(color: colorScheme.outlineVariant.withValues(alpha: 0.2)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 48,
|
||||
height: 48,
|
||||
decoration: BoxDecoration(
|
||||
color: colorScheme.primary.withValues(alpha: 0.15),
|
||||
borderRadius: BorderRadius.circular(AppRadius.lg),
|
||||
),
|
||||
child: Icon(
|
||||
LucideIcons.headset,
|
||||
color: colorScheme.primary,
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
SizedBox(width: AppSpacing.md),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'联系客服',
|
||||
style: AppTextStyles.headlineLarge(context).copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
SizedBox(height: AppSpacing.xs),
|
||||
Text(
|
||||
contact,
|
||||
style: AppTextStyles.bodyMedium(context).copyWith(
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Icon(
|
||||
LucideIcons.copy,
|
||||
size: 16,
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../../core/theme/app_theme.dart';
|
||||
import '../../../core/theme/app_spacing.dart';
|
||||
import '../../../core/theme/app_theme_extension.dart';
|
||||
import '../../../data/models/coin.dart';
|
||||
import '../../../providers/market_provider.dart';
|
||||
import '../../components/coin_icon.dart';
|
||||
import '../main/main_page.dart';
|
||||
|
||||
/// 首頁熱門幣種區塊
|
||||
class HotCoinsSection extends StatelessWidget {
|
||||
@@ -10,153 +14,137 @@ class HotCoinsSection extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
// Title row
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.md),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'熱門幣種',
|
||||
style: AppTextStyles.headlineLarge(context),
|
||||
return Consumer<MarketProvider>(
|
||||
builder: (context, market, _) {
|
||||
// 所有币种,平台代币排首
|
||||
final platformCoins = market.platformCoins;
|
||||
final otherCoins = market.nonPlatformCoins;
|
||||
final coins = [...platformCoins, ...otherCoins];
|
||||
if (coins.isEmpty) return const SizedBox.shrink();
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
// Title row
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.md),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'熱門幣種',
|
||||
style: AppTextStyles.headlineLarge(context),
|
||||
),
|
||||
Text(
|
||||
'更多',
|
||||
style: AppTextStyles.bodyMedium(context).copyWith(
|
||||
color: context.appColors.onSurfaceMuted,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
'更多',
|
||||
style: AppTextStyles.bodyMedium(context).copyWith(
|
||||
color: context.appColors.onSurfaceMuted,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm + AppSpacing.xs),
|
||||
// Card
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surfaceContainer,
|
||||
border: Border.all(
|
||||
color: Theme.of(context).colorScheme.outlineVariant,
|
||||
width: 1,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(AppRadius.xl),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
_CoinRow(
|
||||
symbol: 'BTC',
|
||||
pair: 'BTC/USDT',
|
||||
fullName: 'Bitcoin',
|
||||
price: '68,432.50',
|
||||
change: '+2.35%',
|
||||
isUp: true,
|
||||
const SizedBox(height: AppSpacing.sm + AppSpacing.xs),
|
||||
// Card
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surfaceContainer,
|
||||
border: Border.all(
|
||||
color: Theme.of(context).colorScheme.outlineVariant,
|
||||
width: 1,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(AppRadius.xl),
|
||||
),
|
||||
Divider(
|
||||
height: 1,
|
||||
thickness: 1,
|
||||
color: context.appColors.ghostBorder,
|
||||
child: Column(
|
||||
children: List.generate(coins.length, (index) {
|
||||
return Column(
|
||||
children: [
|
||||
_CoinRow(coin: coins[index]),
|
||||
if (index < coins.length - 1)
|
||||
Divider(
|
||||
height: 1,
|
||||
thickness: 1,
|
||||
color: context.appColors.ghostBorder,
|
||||
),
|
||||
],
|
||||
);
|
||||
}),
|
||||
),
|
||||
_CoinRow(
|
||||
symbol: 'ETH',
|
||||
pair: 'ETH/USDT',
|
||||
fullName: 'Ethereum',
|
||||
price: '3,856.20',
|
||||
change: '+1.82%',
|
||||
isUp: true,
|
||||
),
|
||||
Divider(
|
||||
height: 1,
|
||||
thickness: 1,
|
||||
color: context.appColors.ghostBorder,
|
||||
),
|
||||
_CoinRow(
|
||||
symbol: 'SOL',
|
||||
pair: 'SOL/USDT',
|
||||
fullName: 'Solana',
|
||||
price: '178.65',
|
||||
change: '-0.94%',
|
||||
isUp: false,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CoinRow extends StatelessWidget {
|
||||
const _CoinRow({
|
||||
required this.symbol,
|
||||
required this.pair,
|
||||
required this.fullName,
|
||||
required this.price,
|
||||
required this.change,
|
||||
required this.isUp,
|
||||
});
|
||||
const _CoinRow({required this.coin});
|
||||
|
||||
final String symbol;
|
||||
final String pair;
|
||||
final String fullName;
|
||||
final String price;
|
||||
final String change;
|
||||
final bool isUp;
|
||||
final Coin coin;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final changeColor = isUp
|
||||
final changeColor = coin.isUp
|
||||
? context.appColors.up
|
||||
: context.appColors.down;
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 14, horizontal: AppSpacing.md),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
// Left: avatar + name
|
||||
Row(
|
||||
children: [
|
||||
CoinIcon(
|
||||
symbol: symbol,
|
||||
size: 36,
|
||||
isCircle: false,
|
||||
),
|
||||
const SizedBox(width: AppSpacing.sm + AppSpacing.xs),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
pair,
|
||||
style: AppTextStyles.headlineMedium(context).copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
fullName,
|
||||
style: AppTextStyles.bodySmall(context),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
// Right: price + change
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
price,
|
||||
style: AppTextStyles.numberMedium(context),
|
||||
),
|
||||
Text(
|
||||
change,
|
||||
style: AppTextStyles.labelMedium(context).copyWith(
|
||||
color: changeColor,
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
if (coin.isPlatform == 1) {
|
||||
final mainState = context.findAncestorStateOfType<MainPageState>();
|
||||
mainState?.switchToTrade(coin.code);
|
||||
}
|
||||
},
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 14, horizontal: AppSpacing.md),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
// Left: avatar + name
|
||||
Row(
|
||||
children: [
|
||||
CoinIcon(
|
||||
symbol: coin.code,
|
||||
size: 36,
|
||||
isCircle: false,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
const SizedBox(width: AppSpacing.sm + AppSpacing.xs),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'${coin.code}/USDT',
|
||||
style: AppTextStyles.headlineMedium(context).copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
coin.name,
|
||||
style: AppTextStyles.bodySmall(context),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
// Right: price + change
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
'\$${coin.formattedPrice}',
|
||||
style: AppTextStyles.numberMedium(context),
|
||||
),
|
||||
Text(
|
||||
coin.formattedChange,
|
||||
style: AppTextStyles.labelMedium(context).copyWith(
|
||||
color: changeColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user