feat:参照研听的基础工程
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
|
||||
import '../data/mock_news_repository.dart';
|
||||
import '../data/news_models.dart';
|
||||
|
||||
final newsControllerProvider = StateNotifierProvider<NewsController, NewsState>(
|
||||
(ref) => NewsController(ref.watch(mockNewsRepositoryProvider)),
|
||||
);
|
||||
|
||||
class NewsState {
|
||||
const NewsState({required this.items, required this.refreshedAt});
|
||||
|
||||
final List<NewsItem> items;
|
||||
final DateTime refreshedAt;
|
||||
}
|
||||
|
||||
class NewsController extends StateNotifier<NewsState> {
|
||||
NewsController(this._repository)
|
||||
: super(
|
||||
NewsState(
|
||||
items: _repository.loadFeed(),
|
||||
refreshedAt: DateTime(2026, 6, 18, 16, 11),
|
||||
),
|
||||
);
|
||||
|
||||
final MockNewsRepository _repository;
|
||||
|
||||
void refresh() {
|
||||
state = NewsState(
|
||||
items: _repository.loadFeed(),
|
||||
refreshedAt: DateTime.now(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
|
||||
import '../../../common/domain/metal_type.dart';
|
||||
import 'news_models.dart';
|
||||
|
||||
final mockNewsRepositoryProvider = Provider<MockNewsRepository>(
|
||||
(ref) => MockNewsRepository(),
|
||||
);
|
||||
|
||||
class MockNewsRepository {
|
||||
List<NewsItem> loadFeed() {
|
||||
final base = DateTime(2026, 6, 18, 16, 11);
|
||||
final items = [
|
||||
NewsItem(
|
||||
id: 'news_gold_001',
|
||||
metal: MetalType.gold,
|
||||
title: '金价维持高位震荡,实物金溢价继续分化',
|
||||
source: '金值整理',
|
||||
publishedAt: base.subtract(const Duration(minutes: 18)),
|
||||
summary: '现货价与品牌零售价之间仍有明显价差,持仓估值应优先看材料价值。',
|
||||
body: const [
|
||||
'今日黄金现货价格维持高位震荡,品牌金店挂牌价与现货材料价值之间仍有明显差距。',
|
||||
'对持有者而言,材料价值更适合用于日常估值;对购买者而言,需要额外关注工费、品牌溢价与回收折扣。',
|
||||
],
|
||||
),
|
||||
NewsItem(
|
||||
id: 'news_silver_001',
|
||||
metal: MetalType.silver,
|
||||
title: '白银跟随工业金属情绪回暖,短线波动放大',
|
||||
source: '市场简报',
|
||||
publishedAt: base.subtract(const Duration(hours: 1, minutes: 4)),
|
||||
summary: '银价弹性较强,饰品材料价值和零售购买价差异更大。',
|
||||
body: const [
|
||||
'白银价格今日跟随工业金属情绪回暖,短线波动较黄金更明显。',
|
||||
'银饰通常包含较高加工与零售成本,材料价值占比可能低于用户直觉。',
|
||||
],
|
||||
),
|
||||
NewsItem(
|
||||
id: 'news_platinum_001',
|
||||
metal: MetalType.platinum,
|
||||
title: '铂金回收报价偏谨慎,饰品估值需看纯度',
|
||||
source: '金属观察',
|
||||
publishedAt: base.subtract(const Duration(hours: 2, minutes: 36)),
|
||||
summary: 'PT950 饰品估值建议按克重、纯度和回收折扣分层查看。',
|
||||
body: const [
|
||||
'铂金饰品回收报价通常更依赖门店检测与成色确认,报价口径比现货价格更谨慎。',
|
||||
'记录持仓时建议保留纯度、克重、购买渠道和成本信息,便于后续估值与盈亏回看。',
|
||||
],
|
||||
),
|
||||
];
|
||||
return [...items]..sort((a, b) => b.publishedAt.compareTo(a.publishedAt));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import '../../../common/domain/metal_type.dart';
|
||||
|
||||
class NewsItem {
|
||||
const NewsItem({
|
||||
required this.id,
|
||||
required this.metal,
|
||||
required this.title,
|
||||
required this.source,
|
||||
required this.publishedAt,
|
||||
required this.summary,
|
||||
required this.body,
|
||||
});
|
||||
|
||||
final String id;
|
||||
final MetalType metal;
|
||||
final String title;
|
||||
final String source;
|
||||
final DateTime publishedAt;
|
||||
final String summary;
|
||||
final List<String> body;
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
|
||||
import '../../../common/widgets/adaptive.dart';
|
||||
import '../application/news_controller.dart';
|
||||
|
||||
class NewsPage extends ConsumerWidget {
|
||||
const NewsPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final news = ref.watch(newsControllerProvider);
|
||||
final cs = ShadTheme.of(context).colorScheme;
|
||||
return SafeArea(
|
||||
top: false,
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.fromLTRB(18, 18, 18, 24),
|
||||
children: [
|
||||
Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(
|
||||
maxWidth: Adaptive.contentMaxWidth,
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
'信息整理 · 非投资建议',
|
||||
style: TextStyle(
|
||||
color: cs.mutedForeground,
|
||||
fontSize: 13,
|
||||
),
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () =>
|
||||
ref.read(newsControllerProvider.notifier).refresh(),
|
||||
child: const Text('刷新'),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
for (final item in news.items)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 10),
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: cs.card,
|
||||
border: Border.all(color: cs.border),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
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.shortLabel,
|
||||
style: TextStyle(
|
||||
color: item.metal.color,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'${item.source} · ${item.publishedAt.hour.toString().padLeft(2, '0')}:${item.publishedAt.minute.toString().padLeft(2, '0')}',
|
||||
style: TextStyle(
|
||||
color: cs.mutedForeground,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
item.title,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: cs.foreground,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
item.summary,
|
||||
style: TextStyle(
|
||||
color: cs.mutedForeground,
|
||||
height: 1.5,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user