| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684 |
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:flutter_riverpod/flutter_riverpod.dart';
- import 'package:go_router/go_router.dart';
- import '../../../core/l10n/app_localizations.dart';
- import '../../../core/theme/app_colors.dart';
- import '../../../core/utils/top_toast.dart';
- import '../../../core/utils/number_format.dart';
- import '../../../data/models/asset/withdraw_record.dart';
- import '../../../providers/withdraw_detail_provider.dart';
- class WithdrawDetailScreen extends ConsumerStatefulWidget {
- const WithdrawDetailScreen({
- super.key,
- required this.record,
- required this.isTransfer,
- });
- final WithdrawRecord record;
- final bool isTransfer;
- @override
- ConsumerState<WithdrawDetailScreen> createState() =>
- _WithdrawDetailScreenState();
- }
- class _WithdrawDetailScreenState
- extends ConsumerState<WithdrawDetailScreen> {
- @override
- void initState() {
- super.initState();
- Future.microtask(() {
- ref.read(withdrawDetailProvider.notifier).loadRecord(
- widget.record,
- isTransfer: widget.isTransfer,
- );
- });
- }
- @override
- Widget build(BuildContext context) {
- final state = ref.watch(withdrawDetailProvider);
- final record = state.record ?? widget.record;
- final isDark = Theme.of(context).brightness == Brightness.dark;
- final dividerColor =
- isDark ? AppColors.darkBg : AppColors.lightBgSecondary;
- return Scaffold(
- backgroundColor: isDark ? AppColors.darkBg : AppColors.lightBg,
- appBar: AppBar(
- backgroundColor: isDark ? AppColors.darkBg : AppColors.lightBg,
- leading: IconButton(
- icon: const Icon(Icons.chevron_left, size: 28),
- onPressed: () => context.pop(),
- ),
- title: Text(
- widget.isTransfer ? AppLocalizations.of(context)!.transferDetail : AppLocalizations.of(context)!.withdrawDetail,
- style: const TextStyle(
- fontSize: 17, fontWeight: FontWeight.w600),
- ),
- centerTitle: true,
- ),
- body: state.isLoading
- ? const Center(child: CircularProgressIndicator())
- : SingleChildScrollView(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.stretch,
- children: [
- // ── 数量 ──────────────────────────────────────
- _AmountSection(
- record: record, isTransfer: widget.isTransfer),
- // ── 分隔 ──────────────────────────────────────
- Container(height: 8, color: dividerColor),
- // ── 提现进度 ──────────────────────────────────
- _ProgressSection(
- record: record, isTransfer: widget.isTransfer),
- // ── 分隔 ──────────────────────────────────────
- Container(height: 8, color: dividerColor),
- // ── 信息卡片(链路 / 类型 / 状态)──────────────
- _InfoCards(
- record: record, isTransfer: widget.isTransfer),
- // ── 分隔 ──────────────────────────────────────
- Container(height: 8, color: dividerColor),
- // ── 详细信息 ──────────────────────────────────
- _DetailRows(
- record: record, isTransfer: widget.isTransfer),
- // ── 取消按钮 ──────────────────────────────────
- if (record.canCancel && _within3Minutes(record.createTime))
- Padding(
- padding: const EdgeInsets.fromLTRB(16, 24, 16, 40),
- child: _CancelButton(
- isCancelling: state.isCancelling,
- onCancel: () => _showCancelDialog(context),
- ),
- )
- else
- const SizedBox(height: 40),
- ],
- ),
- ),
- );
- }
- bool _within3Minutes(String createTime) {
- try {
- final dt = DateTime.parse(createTime.replaceFirst(' ', 'T'));
- return DateTime.now().difference(dt).inSeconds <= 180;
- } catch (_) {
- return false;
- }
- }
- void _showCancelDialog(BuildContext ctx) {
- showDialog(
- context: ctx,
- builder: (dialogCtx) => AlertDialog(
- title: Text(AppLocalizations.of(ctx)!.cancelWithdraw),
- content: Text(AppLocalizations.of(ctx)!.confirmCancelWithdraw),
- actions: [
- TextButton(
- onPressed: () => Navigator.pop(dialogCtx),
- child: Text(AppLocalizations.of(ctx)!.cancel),
- ),
- TextButton(
- onPressed: () async {
- Navigator.pop(dialogCtx);
- final ok = await ref
- .read(withdrawDetailProvider.notifier)
- .cancel(isTransfer: widget.isTransfer);
- if (!mounted) return;
- final l10n = AppLocalizations.of(ctx)!;
- ScaffoldMessenger.of(ctx).showSnackBar(
- SnackBar(content: Text(ok ? l10n.withdrawCancelled : l10n.operationFailed)),
- );
- },
- child: Text(AppLocalizations.of(ctx)!.confirm),
- ),
- ],
- ),
- );
- }
- }
- // ── 数量区块(居中,无卡片,与原型一致)──────────────────────────────
- class _AmountSection extends StatelessWidget {
- const _AmountSection({required this.record, required this.isTransfer});
- final WithdrawRecord record;
- final bool isTransfer;
- @override
- Widget build(BuildContext context) {
- final cs = Theme.of(context).colorScheme;
- final coinUnit = record.coin?.baseCoinDisplay.isNotEmpty == true
- ? record.coin!.baseCoinDisplay
- : (record.coin?.coinName.isNotEmpty == true
- ? record.coin!.coinName
- : 'USDT');
- final rawAmount = isTransfer ? record.transferAmount : record.amount;
- final amountStr =
- formatAmount(double.tryParse(rawAmount) ?? 0);
- return Padding(
- padding: const EdgeInsets.fromLTRB(16, 32, 16, 28),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- Text(
- AppLocalizations.of(context)!.amountLabel,
- style: TextStyle(
- color: cs.onSurface.withAlpha(120), fontSize: 12),
- ),
- const SizedBox(height: 10),
- Text(
- '-$amountStr $coinUnit',
- style: const TextStyle(
- color: AppColors.fall,
- fontSize: 30,
- fontWeight: FontWeight.w700,
- letterSpacing: -0.5,
- ),
- ),
- ],
- ),
- );
- }
- }
- // ── 提现进度(垂直步骤条,步骤居中对齐原型)────────────────────────────
- class _ProgressSection extends StatelessWidget {
- const _ProgressSection(
- {required this.record, required this.isTransfer});
- final WithdrawRecord record;
- final bool isTransfer;
- @override
- Widget build(BuildContext context) {
- final cs = Theme.of(context).colorScheme;
- final status = record.status;
- // 步骤 2(等待提现):有申请记录就已进入等待状态
- const step2Done = true;
- // 步骤 3:失败/成功/取消 时完成
- final step3Done = ['2', '3', '4'].contains(status);
- final isFailed = status == '2';
- final isCancelled = status == '4';
- final l10n = AppLocalizations.of(context)!;
- final String step3Title;
- if (isFailed) {
- step3Title = l10n.withdrawFailed;
- } else if (isCancelled) {
- step3Title = l10n.cancelWithdraw;
- } else {
- step3Title = l10n.withdrawSuccess;
- }
- return Padding(
- padding: const EdgeInsets.fromLTRB(16, 0, 16, 24),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- AppLocalizations.of(context)!.withdrawProgress,
- style: TextStyle(
- color: cs.onSurface.withAlpha(120), fontSize: 12),
- ),
- const SizedBox(height: 16),
- // 步骤容器居中,宽 200
- Center(
- child: SizedBox(
- width: 200,
- child: Column(
- children: [
- _VStep(
- done: true,
- failed: false,
- hasLine: true,
- title: l10n.withdrawApplication,
- desc: record.createTime,
- ),
- _VStep(
- done: step2Done,
- failed: false,
- hasLine: true,
- title: l10n.waitingWithdraw,
- desc: record.canCancel ? AppLocalizations.of(context)!.cancelWithdrawHint : '',
- ),
- _VStep(
- done: step3Done,
- failed: isFailed,
- hasLine: false,
- title: step3Title,
- desc: step3Done && record.dealTime.isNotEmpty
- ? record.dealTime
- : '',
- ),
- ],
- ),
- ),
- ),
- ],
- ),
- );
- }
- }
- class _VStep extends StatelessWidget {
- const _VStep({
- required this.done,
- required this.failed,
- required this.hasLine,
- required this.title,
- required this.desc,
- });
- final bool done;
- final bool failed;
- final bool hasLine;
- final String title;
- final String desc;
- @override
- Widget build(BuildContext context) {
- final cs = Theme.of(context).colorScheme;
- final isDark = Theme.of(context).brightness == Brightness.dark;
- final Color borderColor = done
- ? (failed ? AppColors.fall : (isDark ? Colors.white : Colors.black))
- : (isDark ? const Color(0xFF444444) : const Color(0xFFEEEEEE));
- final Color iconColor = done
- ? (failed ? AppColors.fall : (isDark ? Colors.white : Colors.black))
- : (isDark ? const Color(0xFF555555) : const Color(0xFFCCCCCC));
- final Color lineColor = done
- ? (isDark ? Colors.white70 : Colors.black)
- : (isDark ? const Color(0xFF444444) : const Color(0xFFEEEEEE));
- return Row(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- SizedBox(
- width: 24,
- child: Column(
- children: [
- Container(
- width: 24,
- height: 24,
- decoration: BoxDecoration(
- shape: BoxShape.circle,
- color: isDark ? AppColors.darkBg : Colors.white,
- border: Border.all(color: borderColor, width: 2),
- ),
- child: Center(
- child: Icon(
- failed ? Icons.close : Icons.check,
- size: 13,
- color: iconColor,
- ),
- ),
- ),
- if (hasLine)
- Container(
- width: 2,
- height: 44,
- margin: const EdgeInsets.symmetric(vertical: 2),
- color: lineColor,
- ),
- ],
- ),
- ),
- const SizedBox(width: 14),
- Expanded(
- child: Padding(
- padding: EdgeInsets.only(top: 2, bottom: hasLine ? 20 : 0),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- title,
- style: TextStyle(
- color: done
- ? (isDark ? Colors.white : Colors.black)
- : cs.onSurface.withAlpha(100),
- fontSize: 14,
- fontWeight: FontWeight.w600,
- ),
- ),
- if (desc.isNotEmpty) ...[
- const SizedBox(height: 4),
- Text(
- desc,
- style: TextStyle(
- color: cs.onSurface.withAlpha(100),
- fontSize: 10),
- ),
- ],
- ],
- ),
- ),
- ),
- ],
- );
- }
- }
- // ── 信息卡片(3 个独立带边框卡片,间距 10,对齐原型)────────────────────
- class _InfoCards extends StatelessWidget {
- const _InfoCards({required this.record, required this.isTransfer});
- final WithdrawRecord record;
- final bool isTransfer;
- String _localizedStatus(AppLocalizations l10n) {
- switch (record.status) {
- case '0': return l10n.withdrawStatusReviewing;
- case '1': return l10n.withdrawStatusReleasing;
- case '2': return l10n.withdrawStatusFailed;
- case '3': return l10n.withdrawStatusSuccess;
- case '4': return l10n.withdrawStatusCancelled;
- default: return l10n.unknown;
- }
- }
- @override
- Widget build(BuildContext context) {
- final cs = Theme.of(context).colorScheme;
- final isDark = Theme.of(context).brightness == Brightness.dark;
- final baseCoin = record.coin?.baseCoinDisplay.isNotEmpty == true
- ? record.coin!.baseCoinDisplay
- : (record.coin?.coinName.isNotEmpty == true
- ? record.coin!.coinName
- : 'USDT');
- final network = record.coin?.networkName ?? '';
- final l10n = AppLocalizations.of(context)!;
- final chainLabel = isTransfer
- ? l10n.internalLabel
- : (network.isNotEmpty ? '$baseCoin-$network' : baseCoin);
- final typeLabel = isTransfer ? l10n.internalTransfer : l10n.onChainWithdraw;
- Color statusColor;
- switch (record.status) {
- case '3':
- statusColor = AppColors.rise;
- break;
- case '2':
- statusColor = AppColors.fall;
- break;
- case '4':
- statusColor = cs.onSurface.withAlpha(153);
- break;
- default:
- statusColor = AppColors.warning;
- }
- return Padding(
- padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
- child: Row(
- children: [
- _InfoCard(label: AppLocalizations.of(context)!.withdrawNetwork, value: chainLabel, isDark: isDark),
- const SizedBox(width: 10),
- _InfoCard(label: AppLocalizations.of(context)!.typeLabel, value: typeLabel, isDark: isDark),
- const SizedBox(width: 10),
- _InfoCard(
- label: AppLocalizations.of(context)!.statusLabel,
- value: _localizedStatus(l10n),
- valueColor: statusColor,
- isDark: isDark,
- ),
- ],
- ),
- );
- }
- }
- class _InfoCard extends StatelessWidget {
- const _InfoCard({
- required this.label,
- required this.value,
- required this.isDark,
- this.valueColor,
- });
- final String label;
- final String value;
- final bool isDark;
- final Color? valueColor;
- @override
- Widget build(BuildContext context) {
- final cs = Theme.of(context).colorScheme;
- final borderColor =
- isDark ? AppColors.darkDivider : AppColors.lightBorder;
- return Expanded(
- child: Container(
- decoration: BoxDecoration(
- border: Border.all(color: borderColor, width: 1),
- borderRadius: BorderRadius.circular(6),
- ),
- padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 8),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- Text(
- label,
- style: TextStyle(
- color: cs.onSurface.withAlpha(120), fontSize: 11),
- ),
- const SizedBox(height: 6),
- Text(
- value,
- textAlign: TextAlign.center,
- style: TextStyle(
- color: valueColor ?? cs.onSurface,
- fontSize: 12,
- fontWeight: FontWeight.w600,
- ),
- ),
- ],
- ),
- ),
- );
- }
- }
- // ── 详细信息行(平铺,行间 1px 分隔,对齐原型)──────────────────────────
- class _DetailRows extends StatelessWidget {
- const _DetailRows({required this.record, required this.isTransfer});
- final WithdrawRecord record;
- final bool isTransfer;
- @override
- Widget build(BuildContext context) {
- final cs = Theme.of(context).colorScheme;
- final isDark = Theme.of(context).brightness == Brightness.dark;
- final coinUnit = record.coin?.baseCoinDisplay.isNotEmpty == true
- ? record.coin!.baseCoinDisplay
- : (record.coin?.coinName.isNotEmpty == true
- ? record.coin!.coinName
- : 'USDT');
- final feeDouble = double.tryParse(record.coin?.fee ?? '0') ?? 0;
- final feeStr = formatAmount(feeDouble);
- final address = record.address;
- final txHash = record.transactionHashId;
- final divColor =
- isDark ? AppColors.darkDivider : AppColors.lightBgSecondary;
- return Padding(
- padding: const EdgeInsets.symmetric(horizontal: 16),
- child: Column(
- children: [
- // 手续费
- Padding(
- padding: const EdgeInsets.symmetric(vertical: 14),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Text(AppLocalizations.of(context)!.fee,
- style: TextStyle(
- color: cs.onSurface.withAlpha(120), fontSize: 13)),
- Text('$feeStr $coinUnit',
- style: TextStyle(
- color: cs.onSurface,
- fontSize: 13,
- fontWeight: FontWeight.w500)),
- ],
- ),
- ),
- Divider(
- height: 0.5,
- thickness: 0.5,
- color: divColor),
- // 提币地址 / 转入账户
- Padding(
- padding: const EdgeInsets.symmetric(vertical: 14),
- child: Row(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- isTransfer ? AppLocalizations.of(context)!.transferUser : AppLocalizations.of(context)!.withdrawAddress,
- style: TextStyle(
- color: cs.onSurface.withAlpha(120), fontSize: 13),
- ),
- const SizedBox(width: 16),
- Expanded(
- child: Row(
- mainAxisAlignment: MainAxisAlignment.end,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Flexible(
- child: Text(
- address,
- textAlign: TextAlign.right,
- style: TextStyle(
- color: cs.onSurface,
- fontSize: 13,
- fontWeight: FontWeight.w500),
- ),
- ),
- const SizedBox(width: 8),
- GestureDetector(
- onTap: () {
- Clipboard.setData(ClipboardData(text: address));
- showTopToast(context,
- message: AppLocalizations.of(context)!.uidCopied,
- backgroundColor: AppColors.rise);
- },
- child: Icon(Icons.content_copy,
- size: 15,
- color: cs.onSurface.withAlpha(120)),
- ),
- ],
- ),
- ),
- ],
- ),
- ),
- // 哈希(仅链上提现且有值时展示)
- if (!isTransfer && txHash.isNotEmpty) ...[
- Divider(height: 0.5, thickness: 0.5, color: divColor),
- Padding(
- padding: const EdgeInsets.symmetric(vertical: 14),
- child: Row(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- AppLocalizations.of(context)!.txHash,
- style: TextStyle(
- color: cs.onSurface.withAlpha(120), fontSize: 13),
- ),
- const SizedBox(width: 16),
- Expanded(
- child: Row(
- mainAxisAlignment: MainAxisAlignment.end,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Flexible(
- child: Text(
- txHash,
- textAlign: TextAlign.right,
- style: TextStyle(
- color: cs.onSurface,
- fontSize: 13,
- fontWeight: FontWeight.w500),
- ),
- ),
- const SizedBox(width: 8),
- GestureDetector(
- onTap: () {
- Clipboard.setData(ClipboardData(text: txHash));
- ScaffoldMessenger.of(context).showSnackBar(
- SnackBar(
- content: Text(AppLocalizations.of(context)!.copied),
- duration: const Duration(seconds: 1)),
- );
- },
- child: Icon(Icons.content_copy,
- size: 15,
- color: cs.onSurface.withAlpha(120)),
- ),
- ],
- ),
- ),
- ],
- ),
- ),
- ],
- ],
- ),
- );
- }
- }
- // ── 取消按钮 ─────────────────────────────────────────────────────
- class _CancelButton extends StatelessWidget {
- const _CancelButton(
- {required this.isCancelling, required this.onCancel});
- final bool isCancelling;
- final VoidCallback onCancel;
- @override
- Widget build(BuildContext context) {
- return SizedBox(
- width: double.infinity,
- height: 48,
- child: OutlinedButton(
- onPressed: isCancelling ? null : onCancel,
- style: OutlinedButton.styleFrom(
- foregroundColor: AppColors.fall,
- side: const BorderSide(color: AppColors.fall, width: 1),
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(8)),
- ),
- child: isCancelling
- ? const SizedBox(
- width: 20,
- height: 20,
- child: CircularProgressIndicator(
- strokeWidth: 2,
- valueColor:
- AlwaysStoppedAnimation<Color>(AppColors.fall),
- ),
- )
- : Text(AppLocalizations.of(context)!.cancelWithdraw,
- style: const TextStyle(
- fontSize: 15, fontWeight: FontWeight.w600)),
- ),
- );
- }
- }
|