feat:分享功能
This commit is contained in:
@@ -4,10 +4,13 @@ import 'package:go_router/go_router.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import '../../../common/domain/metal_type.dart';
|
||||
import '../../../common/domain/money.dart';
|
||||
import '../../../common/widgets/app_toast.dart';
|
||||
import '../../../common/router/app_router.dart';
|
||||
import '../../../common/util/share_util.dart';
|
||||
import '../../../common/widgets/adaptive.dart';
|
||||
import '../../../common/widgets/circle_back_button.dart';
|
||||
import '../../../common/widgets/prototype_ui.dart';
|
||||
@@ -44,7 +47,7 @@ class InviteRewardPage extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
FilledButton(
|
||||
onPressed: () => _toast(context, '演示:拉起微信 / 系统分享面板'),
|
||||
onPressed: () => toastInfo(msg: '演示:拉起微信 / 系统分享面板'),
|
||||
child: const Text('分享给好友'),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
@@ -62,11 +65,42 @@ class InviteRewardPage extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class ShareCardPage extends ConsumerWidget {
|
||||
class ShareCardPage extends ConsumerStatefulWidget {
|
||||
const ShareCardPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
ConsumerState<ShareCardPage> createState() => _ShareCardPageState();
|
||||
}
|
||||
|
||||
class _ShareCardPageState extends ConsumerState<ShareCardPage> {
|
||||
final GlobalKey _previewKey = GlobalKey();
|
||||
bool _sharing = false;
|
||||
|
||||
Future<void> _shareCard(String owner, {ui.Rect? origin}) async {
|
||||
if (_sharing) return;
|
||||
setState(() => _sharing = true);
|
||||
try {
|
||||
await sharePngFromBoundary(
|
||||
_previewKey,
|
||||
fileName: 'jinzhi_share_card.png',
|
||||
text: '$owner 的贵金属估值卡,已通过金值生成。',
|
||||
subject: '金值贵金属估值卡',
|
||||
sharePositionOrigin: origin ?? shareOriginForContext(context),
|
||||
);
|
||||
} catch (e) {
|
||||
debugPrint('share card failed: $e');
|
||||
await Clipboard.setData(ClipboardData(text: '$owner 的贵金属估值卡,已通过金值生成。'));
|
||||
if (!mounted) return;
|
||||
toastInfo(msg: '图片分享失败,已复制分享文案');
|
||||
} finally {
|
||||
if (mounted) {
|
||||
setState(() => _sharing = false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final auth = ref.watch(authProvider);
|
||||
final currentUser = auth.valueOrNull is LoggedInAuthState
|
||||
? (auth.valueOrNull as LoggedInAuthState).user
|
||||
@@ -79,7 +113,10 @@ class ShareCardPage extends ConsumerWidget {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_SharePreviewCard(owner: owner),
|
||||
RepaintBoundary(
|
||||
key: _previewKey,
|
||||
child: _SharePreviewCard(owner: owner),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
PrototypeCard(
|
||||
padding: EdgeInsets.zero,
|
||||
@@ -100,13 +137,32 @@ class ShareCardPage extends ConsumerWidget {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
FilledButton(
|
||||
Builder(
|
||||
builder: (buttonContext) => FilledButton.icon(
|
||||
onPressed: _sharing
|
||||
? null
|
||||
: () {
|
||||
final origin = shareOriginForContext(buttonContext);
|
||||
_shareCard(owner, origin: origin);
|
||||
},
|
||||
icon: _sharing
|
||||
? const SizedBox(
|
||||
width: 14,
|
||||
height: 14,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: const Icon(Icons.ios_share_outlined),
|
||||
label: Text(_sharing ? '分享中' : '系统分享图片'),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
OutlinedButton(
|
||||
onPressed: () async {
|
||||
await Clipboard.setData(
|
||||
ClipboardData(text: '$owner 的贵金属估值卡,已通过金值生成。'),
|
||||
);
|
||||
if (!context.mounted) return;
|
||||
_toast(context, '分享文案已复制');
|
||||
toastInfo(msg: '分享文案已复制');
|
||||
},
|
||||
child: const Text('复制分享文案'),
|
||||
),
|
||||
@@ -152,7 +208,7 @@ class LocalBackupPage extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
FilledButton(
|
||||
onPressed: () => _toast(context, '已生成本地备份文件'),
|
||||
onPressed: () => toastInfo(msg: '已生成本地备份文件'),
|
||||
child: const Text('生成备份'),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
@@ -213,7 +269,7 @@ class CloudBackupPage extends ConsumerWidget {
|
||||
if (!loggedIn) {
|
||||
context.push(AppRoutes.login);
|
||||
} else {
|
||||
_toast(context, '云同步入口已打开');
|
||||
toastInfo(msg: '云同步入口已打开');
|
||||
}
|
||||
},
|
||||
child: Text(loggedIn ? '开启云备份' : '去登录'),
|
||||
@@ -256,7 +312,7 @@ class WidgetSettingsPage extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
FilledButton(
|
||||
onPressed: () => _toast(context, '演示:打开系统小组件设置'),
|
||||
onPressed: () => toastInfo(msg: '演示:打开系统小组件设置'),
|
||||
child: const Text('添加到桌面'),
|
||||
),
|
||||
],
|
||||
@@ -302,7 +358,7 @@ class PuritySettingsPage extends ConsumerWidget {
|
||||
title: purity,
|
||||
value: (settings.purityPresets[purity] ?? 1)
|
||||
.toStringAsFixed(4),
|
||||
onTap: () => _toast(context, '演示:自定义「$purity」纯度系数'),
|
||||
onTap: () => toastInfo(msg: '演示:自定义「$purity」纯度系数'),
|
||||
),
|
||||
if (purity != group.$2.last)
|
||||
const PrototypeDivider(margin: EdgeInsets.zero),
|
||||
@@ -599,12 +655,12 @@ class AboutPage extends StatelessWidget {
|
||||
const SizedBox(height: 16),
|
||||
_GoldTextAction(
|
||||
label: '提交意见反馈',
|
||||
onTap: () => _toast(context, '演示:打开反馈表单'),
|
||||
onTap: () => toastInfo(msg: '演示:打开反馈表单'),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_GoldTextAction(
|
||||
label: '检查更新',
|
||||
onTap: () => _toast(context, '当前已是最新版本'),
|
||||
onTap: () => toastInfo(msg: '当前已是最新版本'),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -718,7 +774,7 @@ class _InviteCodeCard extends StatelessWidget {
|
||||
const ClipboardData(text: 'JINZHI-8K3F'),
|
||||
);
|
||||
if (!context.mounted) return;
|
||||
_toast(context, '已复制邀请码');
|
||||
toastInfo(msg: '已复制邀请码');
|
||||
},
|
||||
child: const Text(
|
||||
'复制',
|
||||
@@ -1419,7 +1475,3 @@ class _GoldDot extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _toast(BuildContext context, String message) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(message)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user