import 'package:flutter/material.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:shadcn_ui/shadcn_ui.dart'; import '../../../common/config/app_h5_urls.dart'; import '../../../common/util/share_util.dart'; import '../../../common/widgets/app_toast.dart'; import '../../../common/widgets/prototype_ui.dart'; import '../application/news_controller.dart'; class NewsDetailPage extends ConsumerWidget { const NewsDetailPage({super.key, this.id}); final String? id; @override Widget build(BuildContext context, WidgetRef ref) { final news = ref.watch(newsControllerProvider).items; final item = news.firstWhere( (item) => id == null || item.id == id, orElse: () => news.first, ); final cs = ShadTheme.of(context).colorScheme; return Scaffold( backgroundColor: const Color(0xFFFBFAF7), appBar: AppBar( backgroundColor: const Color(0xFFFBFAF7), surfaceTintColor: Colors.transparent, elevation: 0, scrolledUnderElevation: 0, centerTitle: true, leading: IconButton( onPressed: () => Navigator.of(context).pop(), icon: const Icon(Icons.chevron_left, size: 20), ), title: Text( item.metal.label, style: const TextStyle(fontSize: 17, fontWeight: FontWeight.w600), ), actions: [ Builder( builder: (buttonContext) => IconButton( onPressed: () async { final shareText = [ item.title, '${item.source} · ${_timeLabel(item.publishedAt)} · ${item.metal.label}', item.summary, '打开金值查看:${AppH5Urls.baseUrl}/news/detail?id=${item.id}', ].join('\n'); try { await sharePlainText( text: shareText, subject: item.title, sharePositionOrigin: shareOriginForContext(buttonContext), ); } catch (e) { debugPrint('share news failed: $e'); if (!context.mounted) return; await toastInfo(msg: '分享失败'); } }, icon: const Icon(Icons.ios_share_outlined, size: 20), color: const Color(0xFF8A8780), ), ), ], ), body: SafeArea( child: ListView( padding: const EdgeInsets.fromLTRB(0, 8, 0, 24), children: [ PrototypeFrame( child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ const SizedBox(height: 4), PrototypeCard( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( children: [ Container( padding: const EdgeInsets.symmetric( horizontal: 8, vertical: 3, ), decoration: BoxDecoration( color: item.metal.color.withValues(alpha: 0.12), borderRadius: BorderRadius.circular(999), ), child: Text( item.metal.label, style: TextStyle( color: item.metal.color, fontWeight: FontWeight.w700, fontSize: 12, ), ), ), const SizedBox(width: 8), Text( '${item.source} · ${_timeLabel(item.publishedAt)}', style: TextStyle( fontSize: 12, color: cs.mutedForeground, ), ), ], ), const SizedBox(height: 12), Text( item.title, style: const TextStyle( fontSize: 18, fontWeight: FontWeight.w700, height: 1.4, ), ), const SizedBox(height: 12), for (final paragraph in item.body) ...[ Text( paragraph, style: TextStyle( fontSize: 15, height: 1.7, color: cs.foreground, ), ), const SizedBox(height: 12), ], ], ), ), ], ), ), ], ), ), ); } } String _timeLabel(DateTime value) { return '${value.hour.toString().padLeft(2, '0')}:${value.minute.toString().padLeft(2, '0')}'; }