72 lines
2.1 KiB
Dart
72 lines
2.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../../../../core/theme/app_theme.dart';
|
|
import '../../../../core/theme/app_theme_extension.dart';
|
|
import '../../../../core/theme/app_spacing.dart';
|
|
import '../../../components/glass_panel.dart';
|
|
|
|
/// 餘額卡片 — 顯示單個賬戶的 USDT 餘額
|
|
class BalanceCard extends StatelessWidget {
|
|
final String label;
|
|
final String balance;
|
|
|
|
const BalanceCard({
|
|
super.key,
|
|
required this.label,
|
|
required this.balance,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final displayBalance = balance;
|
|
|
|
return SizedBox(
|
|
width: double.infinity, // 確保卡片撐滿寬度
|
|
child: GlassPanel(
|
|
padding: const EdgeInsets.all(20),
|
|
borderRadius: BorderRadius.circular(AppRadius.lg),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
label,
|
|
style: AppTextStyles.bodyMedium(context).copyWith(
|
|
color: context.colors.onSurfaceVariant,
|
|
fontWeight: FontWeight.w400,
|
|
),
|
|
),
|
|
const SizedBox(height: 12),
|
|
FittedBox(
|
|
fit: BoxFit.scaleDown,
|
|
alignment: Alignment.centerLeft,
|
|
child: Text(
|
|
_formatBalance(displayBalance),
|
|
style: AppTextStyles.numberLarge(context),
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
FittedBox(
|
|
fit: BoxFit.scaleDown,
|
|
alignment: Alignment.centerLeft,
|
|
child: Text(
|
|
'\u2248 \$${_formatBalance(displayBalance)} USD',
|
|
style: AppTextStyles.bodyMedium(context).copyWith(
|
|
color: context.appColors.onSurfaceMuted,
|
|
fontWeight: FontWeight.w400,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
String _formatBalance(String balance) {
|
|
final d = double.tryParse(balance) ?? 0;
|
|
return d.toStringAsFixed(2).replaceAllMapped(
|
|
RegExp(r'\B(?=(\d{3})+(?!\d))'),
|
|
(Match m) => ',',
|
|
);
|
|
}
|
|
}
|