chore: prepare yanting monorepo handoff
This commit is contained in:
@@ -0,0 +1,993 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../data/api/report_data_source.dart';
|
||||
import '../../../data/models/models.dart';
|
||||
import '../../../theme/wise_tokens.dart';
|
||||
import '../../../widgets/app_card.dart';
|
||||
import '../../../widgets/badges.dart';
|
||||
import '../../../widgets/mini_player.dart';
|
||||
|
||||
typedef StartModuleAudio =
|
||||
void Function(
|
||||
String audioId,
|
||||
String reportId,
|
||||
String title,
|
||||
int durationSec,
|
||||
);
|
||||
|
||||
class ModuleRendererRegistry {
|
||||
const ModuleRendererRegistry();
|
||||
|
||||
Widget card({
|
||||
required BuildContext context,
|
||||
required DisplayModule module,
|
||||
required ReportDetail report,
|
||||
required ReportDataSource dataSource,
|
||||
required PlayerStateModel player,
|
||||
StartModuleAudio? onStartAudio,
|
||||
VoidCallback? onToggleAudio,
|
||||
void Function(int delta)? onSeekAudio,
|
||||
VoidCallback? onSpeed,
|
||||
}) {
|
||||
final openDetail = module.hasDetailPage
|
||||
? () => Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => ModuleDetailPage(
|
||||
reportId: report.id,
|
||||
module: module,
|
||||
report: report,
|
||||
dataSource: dataSource,
|
||||
registry: this,
|
||||
),
|
||||
),
|
||||
)
|
||||
: null;
|
||||
return AppCard(
|
||||
onTap: openDetail,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_ModuleHeader(module: module),
|
||||
const SizedBox(height: WiseSpacing.x4),
|
||||
_contentFor(
|
||||
context,
|
||||
type: module.type,
|
||||
payload: module.renderMode == 'inline'
|
||||
? module.content
|
||||
: module.preview,
|
||||
report: report,
|
||||
player: player,
|
||||
onStartAudio: onStartAudio,
|
||||
onToggleAudio: onToggleAudio,
|
||||
onSeekAudio: onSeekAudio,
|
||||
onSpeed: onSpeed,
|
||||
compact: module.renderMode != 'inline',
|
||||
),
|
||||
if (module.hasDetailPage) ...[
|
||||
const SizedBox(height: WiseSpacing.x4),
|
||||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: TextButton.icon(
|
||||
onPressed: openDetail,
|
||||
icon: const Icon(Icons.open_in_new),
|
||||
label: const Text('查看详情'),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget page(
|
||||
BuildContext context,
|
||||
String type,
|
||||
JsonMap payload, {
|
||||
ReportDetail? report,
|
||||
}) {
|
||||
return _contentFor(
|
||||
context,
|
||||
type: type,
|
||||
payload: payload,
|
||||
report: report,
|
||||
player: const PlayerStateModel(),
|
||||
compact: false,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _contentFor(
|
||||
BuildContext context, {
|
||||
required String type,
|
||||
required JsonMap payload,
|
||||
required PlayerStateModel player,
|
||||
ReportDetail? report,
|
||||
StartModuleAudio? onStartAudio,
|
||||
VoidCallback? onToggleAudio,
|
||||
void Function(int delta)? onSeekAudio,
|
||||
VoidCallback? onSpeed,
|
||||
bool compact = false,
|
||||
}) {
|
||||
return switch (type) {
|
||||
'basic_info' => _BasicInfo(payload: payload, report: report),
|
||||
'core_insights' => _CoreInsights(payload: payload),
|
||||
'source_compliance' => _SourceCompliance(
|
||||
payload: payload,
|
||||
report: report,
|
||||
),
|
||||
'audio' => _AudioModule(
|
||||
payload: payload,
|
||||
report: report,
|
||||
player: player,
|
||||
onStartAudio: onStartAudio,
|
||||
onToggleAudio: onToggleAudio,
|
||||
onSeekAudio: onSeekAudio,
|
||||
onSpeed: onSpeed,
|
||||
),
|
||||
'institution' => _InstitutionModule(payload: payload, report: report),
|
||||
'executive_overview' => _SectionsModule(
|
||||
payload: payload,
|
||||
compact: compact,
|
||||
),
|
||||
'key_data' => _KeyDataModule(payload: payload, compact: compact),
|
||||
'timeline' => _TimelineModule(payload: payload, compact: compact),
|
||||
'study_guide' => _StudyGuideModule(payload: payload, compact: compact),
|
||||
'structure_graph' => _StructureGraphModule(
|
||||
payload: payload,
|
||||
compact: compact,
|
||||
),
|
||||
'related_sources' => _RelatedSourcesModule(
|
||||
payload: payload,
|
||||
compact: compact,
|
||||
),
|
||||
'differentiated_view' => _DifferentiatedViewModule(
|
||||
payload: payload,
|
||||
compact: compact,
|
||||
),
|
||||
'weaknesses' => _WeaknessesModule(payload: payload, compact: compact),
|
||||
'infographic' => _FallbackModule(type: '信息图', payload: payload),
|
||||
'research_discovery' => _FallbackModule(type: '延伸研究', payload: payload),
|
||||
_ => _FallbackModule(type: type, payload: payload),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class ModuleDetailPage extends StatefulWidget {
|
||||
const ModuleDetailPage({
|
||||
required this.reportId,
|
||||
required this.module,
|
||||
required this.report,
|
||||
required this.dataSource,
|
||||
required this.registry,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final String reportId;
|
||||
final DisplayModule module;
|
||||
final ReportDetail report;
|
||||
final ReportDataSource dataSource;
|
||||
final ModuleRendererRegistry registry;
|
||||
|
||||
@override
|
||||
State<ModuleDetailPage> createState() => _ModuleDetailPageState();
|
||||
}
|
||||
|
||||
class _ModuleDetailPageState extends State<ModuleDetailPage> {
|
||||
late Future<ModuleDetail> future = widget.dataSource.moduleDetail(
|
||||
widget.reportId,
|
||||
widget.module.id,
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text(widget.module.titleCn)),
|
||||
body: FutureBuilder<ModuleDetail>(
|
||||
future: future,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState != ConnectionState.done) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
if (snapshot.hasError) {
|
||||
return Center(
|
||||
child: Text(
|
||||
snapshot.error.toString(),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
);
|
||||
}
|
||||
final detail = snapshot.data!;
|
||||
return ListView(
|
||||
padding: const EdgeInsets.all(WiseSpacing.x4),
|
||||
children: [
|
||||
AppCard(
|
||||
child: widget.registry.page(
|
||||
context,
|
||||
detail.type,
|
||||
detail.content,
|
||||
report: widget.report,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x3),
|
||||
Text(
|
||||
'缓存版本 ${detail.cacheVersion}',
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ModuleHeader extends StatelessWidget {
|
||||
const _ModuleHeader({required this.module});
|
||||
|
||||
final DisplayModule module;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
module.titleCn,
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
),
|
||||
if (module.layer.isNotEmpty)
|
||||
AppBadge(text: module.layer.toUpperCase(), kind: BadgeKind.brand),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _BasicInfo extends StatelessWidget {
|
||||
const _BasicInfo({required this.payload, required this.report});
|
||||
|
||||
final JsonMap payload;
|
||||
final ReportDetail? report;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final topics = asStringList(payload['topics']).isEmpty
|
||||
? report?.topics ?? const []
|
||||
: asStringList(payload['topics']);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
asString(
|
||||
payload['summary_cn'],
|
||||
asString(payload['scope_cn'], report?.oneLiner ?? ''),
|
||||
),
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x2),
|
||||
Wrap(
|
||||
spacing: WiseSpacing.x2,
|
||||
runSpacing: WiseSpacing.x2,
|
||||
children: [
|
||||
for (final topic in topics) AppBadge(text: topic),
|
||||
if (report?.releasedAt != null)
|
||||
AppBadge(text: formatDate(report!.releasedAt)),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CoreInsights extends StatelessWidget {
|
||||
const _CoreInsights({required this.payload});
|
||||
|
||||
final JsonMap payload;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final points = asMapList(payload['points']);
|
||||
if (points.isEmpty) return _TextLines(payload: payload);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
for (final point in points)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: WiseSpacing.x3),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
AppBadge(
|
||||
text: _kindLabel(asString(point['kind'])),
|
||||
kind: _kindBadge(asString(point['kind'])),
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x1),
|
||||
Text(
|
||||
asString(point['text']),
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SourceCompliance extends StatelessWidget {
|
||||
const _SourceCompliance({required this.payload, required this.report});
|
||||
|
||||
final JsonMap payload;
|
||||
final ReportDetail? report;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final institution = report?.institution;
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (asString(payload['source_note']).isNotEmpty)
|
||||
Text(
|
||||
asString(payload['source_note']),
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
if (institution != null) ...[
|
||||
const SizedBox(height: WiseSpacing.x4),
|
||||
Text('发布机构', style: Theme.of(context).textTheme.titleMedium),
|
||||
const SizedBox(height: WiseSpacing.x2),
|
||||
_InfoLine(label: '机构名称', value: institution.nameCn),
|
||||
if (institution.nameEn.isNotEmpty)
|
||||
_InfoLine(label: '英文名称', value: institution.nameEn),
|
||||
if (institution.institutionType.isNotEmpty)
|
||||
_InfoLine(
|
||||
label: '机构类型',
|
||||
value: _institutionTypeLabel(institution.institutionType),
|
||||
),
|
||||
if (institution.sourceTier.isNotEmpty)
|
||||
_InfoLine(label: '来源层级', value: institution.sourceTier),
|
||||
if (institution.reportCount > 0)
|
||||
_InfoLine(label: '收录报告', value: '${institution.reportCount} 份'),
|
||||
if (institution.coveredTopics.isNotEmpty)
|
||||
_InfoLine(
|
||||
label: '覆盖主题',
|
||||
value: institution.coveredTopics.join('、'),
|
||||
),
|
||||
if (institution.websiteUrl.isNotEmpty)
|
||||
_InfoLine(label: '官网', value: institution.websiteUrl),
|
||||
if (institution.introCn.isNotEmpty)
|
||||
_InfoLine(label: '说明', value: institution.introCn),
|
||||
],
|
||||
if (asString(payload['copyright_cn']).isNotEmpty) ...[
|
||||
const SizedBox(height: WiseSpacing.x4),
|
||||
Text(
|
||||
asString(payload['copyright_cn']),
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
const SizedBox(height: WiseSpacing.x3),
|
||||
DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0x109A6500),
|
||||
borderRadius: BorderRadius.circular(WiseRadius.sm),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(WiseSpacing.x3),
|
||||
child: Text(
|
||||
asString(payload['disclaimer'], '本内容为公开/授权研报的结构化解读,不构成投资建议。'),
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.bodySmall?.copyWith(color: WiseColors.warning),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _InfoLine extends StatelessWidget {
|
||||
const _InfoLine({required this.label, required this.value});
|
||||
|
||||
final String label;
|
||||
final String value;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (value.isEmpty) return const SizedBox.shrink();
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: WiseSpacing.x2),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.labelSmall?.copyWith(color: WiseColors.ink700),
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x1),
|
||||
Text(value, style: Theme.of(context).textTheme.bodyMedium),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _AudioModule extends StatelessWidget {
|
||||
const _AudioModule({
|
||||
required this.payload,
|
||||
required this.report,
|
||||
required this.player,
|
||||
this.onStartAudio,
|
||||
this.onToggleAudio,
|
||||
this.onSeekAudio,
|
||||
this.onSpeed,
|
||||
});
|
||||
|
||||
final JsonMap payload;
|
||||
final ReportDetail? report;
|
||||
final PlayerStateModel player;
|
||||
final StartModuleAudio? onStartAudio;
|
||||
final VoidCallback? onToggleAudio;
|
||||
final void Function(int delta)? onSeekAudio;
|
||||
final VoidCallback? onSpeed;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final title = asString(payload['title_cn'], report?.titleCn ?? '音频解读');
|
||||
final audioId = asString(
|
||||
payload['audio_id'],
|
||||
'local_${report?.id ?? title.hashCode}',
|
||||
);
|
||||
final duration = asInt(payload['duration_sec'], 180);
|
||||
return PlayerCard(
|
||||
title: title,
|
||||
durationSec: duration,
|
||||
player: player,
|
||||
onStart: () =>
|
||||
onStartAudio?.call(audioId, report?.id ?? '', title, duration),
|
||||
onToggle: onToggleAudio ?? () {},
|
||||
onSeek: onSeekAudio ?? (_) {},
|
||||
onSpeed: onSpeed ?? () {},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _InstitutionModule extends StatelessWidget {
|
||||
const _InstitutionModule({required this.payload, required this.report});
|
||||
|
||||
final JsonMap payload;
|
||||
final ReportDetail? report;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final name = asString(payload['name_cn'], report?.institution.nameCn ?? '');
|
||||
return Row(
|
||||
children: [
|
||||
const Icon(Icons.account_balance_outlined, color: WiseColors.primary),
|
||||
const SizedBox(width: WiseSpacing.x2),
|
||||
Expanded(
|
||||
child: Text(name, style: Theme.of(context).textTheme.bodyMedium),
|
||||
),
|
||||
Text(
|
||||
'${asInt(payload['report_count'], report?.institution.reportCount ?? 0)} 份',
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SectionsModule extends StatelessWidget {
|
||||
const _SectionsModule({required this.payload, required this.compact});
|
||||
|
||||
final JsonMap payload;
|
||||
final bool compact;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final summary = asString(
|
||||
payload['preview_summary'],
|
||||
asString(payload['intro_cn']),
|
||||
);
|
||||
final sections = asMapList(payload['sections']);
|
||||
if (compact) return _Preview(payload: payload);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (summary.isNotEmpty)
|
||||
Text(summary, style: Theme.of(context).textTheme.bodyMedium),
|
||||
for (final section in sections) ...[
|
||||
const SizedBox(height: WiseSpacing.x3),
|
||||
Text(
|
||||
asString(section['heading']),
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x1),
|
||||
Text(
|
||||
asString(section['body']),
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _KeyDataModule extends StatelessWidget {
|
||||
const _KeyDataModule({required this.payload, required this.compact});
|
||||
|
||||
final JsonMap payload;
|
||||
final bool compact;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (compact) return _Preview(payload: payload);
|
||||
final rows = asMapList(payload['rows']);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
for (final row in rows)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: WiseSpacing.x4),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
asString(row['metric']),
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x1),
|
||||
Text(
|
||||
_valueWithUnit(row),
|
||||
style: Theme.of(context).textTheme.bodyLarge,
|
||||
),
|
||||
if (asString(
|
||||
row['judgment'],
|
||||
asString(row['importance']),
|
||||
).isNotEmpty) ...[
|
||||
const SizedBox(height: WiseSpacing.x1),
|
||||
Text(
|
||||
asString(row['judgment'], asString(row['importance'])),
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
],
|
||||
if (asString(row['importance']).isNotEmpty &&
|
||||
asString(row['importance']) !=
|
||||
asString(row['judgment'])) ...[
|
||||
const SizedBox(height: WiseSpacing.x1),
|
||||
Text(
|
||||
asString(row['importance']),
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _TimelineModule extends StatelessWidget {
|
||||
const _TimelineModule({required this.payload, required this.compact});
|
||||
|
||||
final JsonMap payload;
|
||||
final bool compact;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (compact) return _Preview(payload: payload);
|
||||
final events = asMapList(payload['events']);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
for (final event in events)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: WiseSpacing.x4),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (asString(event['date']).isNotEmpty)
|
||||
Text(
|
||||
asString(event['date']),
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.labelSmall?.copyWith(color: WiseColors.primary),
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x1),
|
||||
Text(
|
||||
asString(event['event']),
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x1),
|
||||
Text(
|
||||
asString(event['impact']),
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _StudyGuideModule extends StatelessWidget {
|
||||
const _StudyGuideModule({required this.payload, required this.compact});
|
||||
|
||||
final JsonMap payload;
|
||||
final bool compact;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (compact) return _Preview(payload: payload);
|
||||
final faqs = asMapList(payload['faq_items']);
|
||||
final glossary = asMapList(payload['glossary']);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (asString(payload['intro_cn']).isNotEmpty)
|
||||
Text(
|
||||
asString(payload['intro_cn']),
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
for (final item in faqs)
|
||||
ExpansionTile(
|
||||
tilePadding: EdgeInsets.zero,
|
||||
title: Text(asString(item['question'])),
|
||||
children: [
|
||||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
asString(item['answer']),
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (glossary.isNotEmpty) ...[
|
||||
const SizedBox(height: WiseSpacing.x3),
|
||||
Wrap(
|
||||
spacing: WiseSpacing.x2,
|
||||
runSpacing: WiseSpacing.x2,
|
||||
children: [
|
||||
for (final item in glossary)
|
||||
AppBadge(
|
||||
text:
|
||||
'${asString(item['term'])}: ${asString(item['definition'])}',
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _StructureGraphModule extends StatelessWidget {
|
||||
const _StructureGraphModule({required this.payload, required this.compact});
|
||||
|
||||
final JsonMap payload;
|
||||
final bool compact;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (compact) return _Preview(payload: payload);
|
||||
final nodes = asMapList(payload['nodes']);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
asString(payload['root']),
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x3),
|
||||
for (final node in nodes)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: WiseSpacing.x4),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
asString(node['label']),
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x1),
|
||||
for (final child in asStringList(node['children']))
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: WiseSpacing.x1),
|
||||
child: Text(
|
||||
child,
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _RelatedSourcesModule extends StatelessWidget {
|
||||
const _RelatedSourcesModule({required this.payload, required this.compact});
|
||||
|
||||
final JsonMap payload;
|
||||
final bool compact;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final items = asMapList(payload['items'] ?? payload['sources']);
|
||||
if (items.isEmpty) return _Preview(payload: payload);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
for (final item in items)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: WiseSpacing.x4),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
asString(item['title']),
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x1),
|
||||
Text(
|
||||
asString(item['summary_cn'], asString(item['source_name'])),
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _DifferentiatedViewModule extends StatelessWidget {
|
||||
const _DifferentiatedViewModule({
|
||||
required this.payload,
|
||||
required this.compact,
|
||||
});
|
||||
|
||||
final JsonMap payload;
|
||||
final bool compact;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (compact) return _Preview(payload: payload);
|
||||
final items = asMapList(payload['divergences']);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
for (final item in items)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: WiseSpacing.x4),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
asString(item['topic']),
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x2),
|
||||
if (asString(item['consensus_view']).isNotEmpty) ...[
|
||||
Text(
|
||||
'常见观点',
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.labelSmall?.copyWith(color: WiseColors.ink700),
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x1),
|
||||
Text(
|
||||
asString(item['consensus_view']),
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x2),
|
||||
],
|
||||
if (asString(item['report_position']).isNotEmpty) ...[
|
||||
Text(
|
||||
'报告观点',
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.labelSmall?.copyWith(color: WiseColors.primary),
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x1),
|
||||
Text(
|
||||
asString(item['report_position']),
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _WeaknessesModule extends StatelessWidget {
|
||||
const _WeaknessesModule({required this.payload, required this.compact});
|
||||
|
||||
final JsonMap payload;
|
||||
final bool compact;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (compact) return _Preview(payload: payload);
|
||||
final items = asMapList(payload['items']);
|
||||
final verificationNotes = asStringList(payload['verification_notes']);
|
||||
final counterEvidence = {
|
||||
for (final item in items)
|
||||
if (asString(item['counter_evidence']).isNotEmpty)
|
||||
asString(item['counter_evidence']),
|
||||
}.toList();
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (asString(payload['disclaimer_cn']).isNotEmpty)
|
||||
Text(
|
||||
asString(payload['disclaimer_cn']),
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
for (final item in items)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
top: WiseSpacing.x3,
|
||||
bottom: WiseSpacing.x2,
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
asString(item['topic']),
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x1),
|
||||
Text(
|
||||
asString(item['weakness']),
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (verificationNotes.isNotEmpty || counterEvidence.isNotEmpty) ...[
|
||||
const SizedBox(height: WiseSpacing.x2),
|
||||
DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0x109A6500),
|
||||
borderRadius: BorderRadius.circular(WiseRadius.sm),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(WiseSpacing.x3),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'需要继续验证',
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.labelSmall?.copyWith(color: WiseColors.warning),
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x1),
|
||||
for (final note
|
||||
in verificationNotes.isNotEmpty
|
||||
? verificationNotes
|
||||
: counterEvidence)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: WiseSpacing.x1),
|
||||
child: Text(
|
||||
note,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Preview extends StatelessWidget {
|
||||
const _Preview({required this.payload});
|
||||
|
||||
final JsonMap payload;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final headline = asString(
|
||||
payload['preview_headline'],
|
||||
asString(payload['preview_summary'], asString(payload['root'])),
|
||||
);
|
||||
final highlights = asStringList(payload['highlights']);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (headline.isNotEmpty)
|
||||
Text(headline, style: Theme.of(context).textTheme.bodyMedium),
|
||||
for (final item in highlights.take(3))
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: WiseSpacing.x1),
|
||||
child: Text(
|
||||
'• $item',
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _TextLines extends StatelessWidget {
|
||||
const _TextLines({required this.payload});
|
||||
|
||||
final JsonMap payload;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final values = payload.entries
|
||||
.where(
|
||||
(entry) => entry.value != null && entry.value.toString().isNotEmpty,
|
||||
)
|
||||
.map((entry) => '${entry.key}: ${entry.value}')
|
||||
.take(5)
|
||||
.join('\n');
|
||||
return Text(
|
||||
values.isEmpty ? '该模块暂无可展示内容。' : values,
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _FallbackModule extends StatelessWidget {
|
||||
const _FallbackModule({required this.type, required this.payload});
|
||||
|
||||
final String type;
|
||||
final JsonMap payload;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
AppBadge(text: '未知模块:$type', kind: BadgeKind.warning),
|
||||
const SizedBox(height: WiseSpacing.x2),
|
||||
_Preview(payload: payload),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _kindLabel(String kind) => switch (kind) {
|
||||
'view' => '观点',
|
||||
'number' => '数字',
|
||||
'risk' => '风险',
|
||||
_ => '要点',
|
||||
};
|
||||
|
||||
BadgeKind _kindBadge(String kind) => switch (kind) {
|
||||
'risk' => BadgeKind.warning,
|
||||
'number' => BadgeKind.audio,
|
||||
_ => BadgeKind.brand,
|
||||
};
|
||||
|
||||
String _valueWithUnit(JsonMap row) {
|
||||
final value = asString(row['value']);
|
||||
final unit = asString(row['unit']);
|
||||
if (unit.isEmpty) return value;
|
||||
return '$value $unit';
|
||||
}
|
||||
|
||||
String _institutionTypeLabel(String value) => switch (value) {
|
||||
'international_org' => '国际组织',
|
||||
'official' => '官方机构',
|
||||
'industry_org' => '行业组织',
|
||||
'asset_manager' => '资管机构',
|
||||
'bank_research' => '银行研究',
|
||||
'partner' => '合作机构',
|
||||
_ => value,
|
||||
};
|
||||
@@ -0,0 +1,199 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../data/api/report_data_source.dart';
|
||||
import '../../data/models/models.dart';
|
||||
import '../../theme/wise_tokens.dart';
|
||||
import '../../widgets/app_buttons.dart';
|
||||
import '../../widgets/app_card.dart';
|
||||
import '../../widgets/badges.dart';
|
||||
import '../../widgets/mini_player.dart';
|
||||
import '../../widgets/sheets.dart';
|
||||
import '../../widgets/states.dart';
|
||||
import 'modules/renderer_registry.dart';
|
||||
|
||||
class ReportDetailPage extends StatefulWidget {
|
||||
const ReportDetailPage({
|
||||
required this.reportId,
|
||||
required this.dataSource,
|
||||
this.player = const PlayerStateModel(),
|
||||
this.onStartAudio,
|
||||
this.onToggleAudio,
|
||||
this.onSeekAudio,
|
||||
this.onSpeed,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final String reportId;
|
||||
final ReportDataSource dataSource;
|
||||
final PlayerStateModel player;
|
||||
final void Function(
|
||||
String audioId,
|
||||
String reportId,
|
||||
String title,
|
||||
int durationSec,
|
||||
)?
|
||||
onStartAudio;
|
||||
final VoidCallback? onToggleAudio;
|
||||
final void Function(int delta)? onSeekAudio;
|
||||
final VoidCallback? onSpeed;
|
||||
|
||||
@override
|
||||
State<ReportDetailPage> createState() => _ReportDetailPageState();
|
||||
}
|
||||
|
||||
class _ReportDetailPageState extends State<ReportDetailPage> {
|
||||
static const registry = ModuleRendererRegistry();
|
||||
late Future<ReportDetail> future = widget.dataSource.reportDetail(
|
||||
widget.reportId,
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('研报详情')),
|
||||
body: FutureBuilder<ReportDetail>(
|
||||
future: future,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState != ConnectionState.done) {
|
||||
return const LoadingState();
|
||||
}
|
||||
if (snapshot.hasError) {
|
||||
return ErrorState(
|
||||
message: snapshot.error.toString(),
|
||||
onRetry: () => setState(
|
||||
() => future = widget.dataSource.reportDetail(widget.reportId),
|
||||
),
|
||||
);
|
||||
}
|
||||
final detail = snapshot.data!;
|
||||
return ListView(
|
||||
padding: const EdgeInsets.all(WiseSpacing.x4),
|
||||
children: [
|
||||
AppCard(
|
||||
color: WiseColors.secondary200,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Wrap(
|
||||
spacing: WiseSpacing.x2,
|
||||
runSpacing: WiseSpacing.x2,
|
||||
children: [
|
||||
AppBadge(
|
||||
text: detail.interpretationLabel,
|
||||
kind: BadgeKind.brand,
|
||||
),
|
||||
if (detail.hasAudio)
|
||||
const AppBadge(
|
||||
text: '音频',
|
||||
icon: Icons.graphic_eq,
|
||||
kind: BadgeKind.audio,
|
||||
),
|
||||
AppBadge(
|
||||
text: asString(detail.source['source_tier']),
|
||||
icon: Icons.verified_outlined,
|
||||
kind: BadgeKind.tier,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x3),
|
||||
Text(
|
||||
detail.titleCn,
|
||||
maxLines: 3,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme.of(context).textTheme.headlineSmall,
|
||||
),
|
||||
if (detail.oneLiner.isNotEmpty) ...[
|
||||
const SizedBox(height: WiseSpacing.x2),
|
||||
Text(
|
||||
detail.oneLiner,
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
],
|
||||
const SizedBox(height: WiseSpacing.x3),
|
||||
Text(
|
||||
'${detail.institution.nameCn} · ${formatDate(detail.releasedAt)}',
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x4),
|
||||
_ActionBar(detail: detail),
|
||||
const SizedBox(height: WiseSpacing.x4),
|
||||
_Toc(modules: detail.modules),
|
||||
const SizedBox(height: WiseSpacing.x4),
|
||||
for (final module in detail.modules) ...[
|
||||
registry.card(
|
||||
context: context,
|
||||
module: module,
|
||||
report: detail,
|
||||
dataSource: widget.dataSource,
|
||||
player: widget.player,
|
||||
onStartAudio: widget.onStartAudio,
|
||||
onToggleAudio: widget.onToggleAudio,
|
||||
onSeekAudio: widget.onSeekAudio,
|
||||
onSpeed: widget.onSpeed,
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x4),
|
||||
],
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ActionBar extends StatelessWidget {
|
||||
const _ActionBar({required this.detail});
|
||||
|
||||
final ReportDetail detail;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: AppButton(
|
||||
label: '收藏',
|
||||
icon: Icons.favorite_border,
|
||||
kind: AppButtonKind.ghost,
|
||||
onPressed: () => showLoginSheet(context, reason: '登录后保存到你的收藏'),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: WiseSpacing.x2),
|
||||
Expanded(
|
||||
child: AppButton(
|
||||
label: '原文',
|
||||
icon: Icons.open_in_new,
|
||||
kind: AppButtonKind.ghost,
|
||||
onPressed: () => showOutboundSheet(context, title: detail.titleCn),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Toc extends StatelessWidget {
|
||||
const _Toc({required this.modules});
|
||||
|
||||
final List<DisplayModule> modules;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (modules.isEmpty) return const SizedBox.shrink();
|
||||
return SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: [
|
||||
for (final module in modules)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: WiseSpacing.x2),
|
||||
child: AppBadge(text: module.titleCn, kind: BadgeKind.brand),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../data/api/report_data_source.dart';
|
||||
import '../../data/models/models.dart';
|
||||
import '../../routing/app_routes.dart';
|
||||
import '../../theme/wise_tokens.dart';
|
||||
import '../../widgets/badges.dart';
|
||||
import '../../widgets/mini_player.dart';
|
||||
import '../../widgets/states.dart';
|
||||
import '../shared/report_card_widget.dart';
|
||||
|
||||
class FeedPage extends StatefulWidget {
|
||||
const FeedPage({
|
||||
required this.dataSource,
|
||||
required this.onPlay,
|
||||
this.player = const PlayerStateModel(),
|
||||
this.onStartModuleAudio,
|
||||
this.onToggleAudio,
|
||||
this.onSeekAudio,
|
||||
this.onSpeed,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final ReportDataSource dataSource;
|
||||
final void Function(AudioItem item) onPlay;
|
||||
final PlayerStateModel player;
|
||||
final void Function(String audioId, String reportId, String title, int durationSec)? onStartModuleAudio;
|
||||
final VoidCallback? onToggleAudio;
|
||||
final void Function(int delta)? onSeekAudio;
|
||||
final VoidCallback? onSpeed;
|
||||
|
||||
@override
|
||||
State<FeedPage> createState() => _FeedPageState();
|
||||
}
|
||||
|
||||
class _FeedPageState extends State<FeedPage> {
|
||||
String topic = '全部';
|
||||
late Future<List<ReportCardModel>> future = widget.dataSource.recommended();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder<List<ReportCardModel>>(
|
||||
future: future,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState != ConnectionState.done) return const LoadingState();
|
||||
if (snapshot.hasError) return ErrorState(message: snapshot.error.toString(), onRetry: () => setState(() => future = widget.dataSource.recommended()));
|
||||
final items = snapshot.data ?? const [];
|
||||
final topics = ['全部', ...{for (final item in items) ...item.topics}];
|
||||
final visible = topic == '全部' ? items : items.where((item) => item.topics.contains(topic)).toList();
|
||||
if (items.isEmpty) return const EmptyState(title: '暂无可推荐的研报解读', message: '稍后再来看看最新内容');
|
||||
return ListView(
|
||||
padding: const EdgeInsets.all(WiseSpacing.x4),
|
||||
children: [
|
||||
SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: [
|
||||
for (final t in topics)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: WiseSpacing.x2),
|
||||
child: AppChip(label: t, selected: t == topic, onTap: () => setState(() => topic = t)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x3),
|
||||
if (visible.isEmpty)
|
||||
EmptyState(title: '暂无可推荐的研报解读', message: '换个主题,或去研报页看看全部内容', icon: Icons.filter_alt_off)
|
||||
else ...[
|
||||
ReportCardWidget(
|
||||
report: visible.first,
|
||||
hero: true,
|
||||
onTap: () => openReportDetail(
|
||||
context,
|
||||
widget.dataSource,
|
||||
visible.first,
|
||||
player: widget.player,
|
||||
onStartAudio: widget.onStartModuleAudio,
|
||||
onToggleAudio: widget.onToggleAudio,
|
||||
onSeekAudio: widget.onSeekAudio,
|
||||
onSpeed: widget.onSpeed,
|
||||
),
|
||||
onPlayTap: () => playFromReport(widget.onPlay, visible.first),
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x5),
|
||||
Text('最新解读', style: Theme.of(context).textTheme.titleMedium),
|
||||
const SizedBox(height: WiseSpacing.x3),
|
||||
for (final report in visible.skip(1)) ...[
|
||||
ReportCardWidget(
|
||||
report: report,
|
||||
onTap: () => openReportDetail(
|
||||
context,
|
||||
widget.dataSource,
|
||||
report,
|
||||
player: widget.player,
|
||||
onStartAudio: widget.onStartModuleAudio,
|
||||
onToggleAudio: widget.onToggleAudio,
|
||||
onSeekAudio: widget.onSeekAudio,
|
||||
onSpeed: widget.onSpeed,
|
||||
),
|
||||
onPlayTap: () => playFromReport(widget.onPlay, report),
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x3),
|
||||
],
|
||||
],
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void playFromReport(void Function(AudioItem item) onPlay, ReportCardModel report) {
|
||||
onPlay(
|
||||
AudioItem(
|
||||
audioId: 'local_${report.id}',
|
||||
reportId: report.id,
|
||||
titleCn: report.titleCn,
|
||||
reportTitleCn: report.titleCn,
|
||||
durationSec: 180,
|
||||
institution: report.institution,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../data/api/report_data_source.dart';
|
||||
import '../../data/models/models.dart';
|
||||
import '../../routing/app_routes.dart';
|
||||
import '../../theme/wise_tokens.dart';
|
||||
import '../../widgets/app_buttons.dart';
|
||||
import '../../widgets/app_card.dart';
|
||||
import '../../widgets/badges.dart';
|
||||
import '../../widgets/sheets.dart';
|
||||
import '../../widgets/states.dart';
|
||||
import '../shared/report_card_widget.dart';
|
||||
|
||||
class InstitutionDetailPage extends StatefulWidget {
|
||||
const InstitutionDetailPage({required this.institutionId, required this.dataSource, super.key});
|
||||
|
||||
final String institutionId;
|
||||
final ReportDataSource dataSource;
|
||||
|
||||
@override
|
||||
State<InstitutionDetailPage> createState() => _InstitutionDetailPageState();
|
||||
}
|
||||
|
||||
class _InstitutionDetailPageState extends State<InstitutionDetailPage> {
|
||||
late Future<Institution> future = widget.dataSource.institutionDetail(widget.institutionId);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('机构主页')),
|
||||
body: FutureBuilder<Institution>(
|
||||
future: future,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState != ConnectionState.done) return const LoadingState();
|
||||
if (snapshot.hasError) return ErrorState(message: snapshot.error.toString(), onRetry: () => setState(() => future = widget.dataSource.institutionDetail(widget.institutionId)));
|
||||
final item = snapshot.data!;
|
||||
return ListView(
|
||||
padding: const EdgeInsets.all(WiseSpacing.x4),
|
||||
children: [
|
||||
AppCard(
|
||||
color: WiseColors.secondary200,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(item.nameCn, style: Theme.of(context).textTheme.headlineSmall),
|
||||
if (item.nameEn.isNotEmpty) Text(item.nameEn, style: Theme.of(context).textTheme.bodyMedium),
|
||||
const SizedBox(height: WiseSpacing.x3),
|
||||
Wrap(
|
||||
spacing: WiseSpacing.x2,
|
||||
runSpacing: WiseSpacing.x2,
|
||||
children: [
|
||||
AppBadge(text: item.sourceTier, icon: Icons.verified_outlined, kind: BadgeKind.tier),
|
||||
AppBadge(text: '${item.reportCount} 份研报', kind: BadgeKind.brand),
|
||||
for (final topic in item.coveredTopics) AppBadge(text: topic),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x3),
|
||||
if (item.introCn.isNotEmpty)
|
||||
AppCard(child: Text(item.introCn, style: Theme.of(context).textTheme.bodyMedium)),
|
||||
const SizedBox(height: WiseSpacing.x3),
|
||||
if (item.credibilityNote.isNotEmpty)
|
||||
AppCard(
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Icon(Icons.verified_user_outlined, color: WiseColors.positive),
|
||||
const SizedBox(width: WiseSpacing.x2),
|
||||
Expanded(child: Text(item.credibilityNote, style: Theme.of(context).textTheme.bodyMedium)),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x5),
|
||||
Text('最新研报', style: Theme.of(context).textTheme.titleMedium),
|
||||
const SizedBox(height: WiseSpacing.x3),
|
||||
if (item.recentReports.isEmpty)
|
||||
const EmptyState(title: '机构暂无研报', message: '稍后再试', icon: Icons.article_outlined)
|
||||
else
|
||||
for (final report in item.recentReports) ...[
|
||||
ReportCardWidget(
|
||||
report: report,
|
||||
onTap: () => openReportDetail(context, widget.dataSource, report),
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x3),
|
||||
],
|
||||
AppButton(
|
||||
label: '了解相关服务',
|
||||
icon: Icons.open_in_new,
|
||||
kind: AppButtonKind.ghost,
|
||||
expand: true,
|
||||
onPressed: () => showOutboundSheet(context, title: item.nameCn),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../data/api/report_data_source.dart';
|
||||
import '../../data/models/models.dart';
|
||||
import '../../routing/app_routes.dart';
|
||||
import '../../theme/wise_tokens.dart';
|
||||
import '../../widgets/app_card.dart';
|
||||
import '../../widgets/badges.dart';
|
||||
import '../../widgets/states.dart';
|
||||
|
||||
class InstitutionsPage extends StatefulWidget {
|
||||
const InstitutionsPage({required this.dataSource, super.key});
|
||||
|
||||
final ReportDataSource dataSource;
|
||||
|
||||
@override
|
||||
State<InstitutionsPage> createState() => _InstitutionsPageState();
|
||||
}
|
||||
|
||||
class _InstitutionsPageState extends State<InstitutionsPage> {
|
||||
late Future<List<Institution>> future = widget.dataSource.institutions();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder<List<Institution>>(
|
||||
future: future,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState != ConnectionState.done) return const LoadingState();
|
||||
if (snapshot.hasError) return ErrorState(message: snapshot.error.toString(), onRetry: () => setState(() => future = widget.dataSource.institutions()));
|
||||
final items = [...snapshot.data ?? const <Institution>[]]..sort((a, b) => b.reportCount.compareTo(a.reportCount));
|
||||
if (items.isEmpty) return const EmptyState(title: '暂无机构信息', message: '稍后再试', icon: Icons.account_balance_outlined);
|
||||
return ListView(
|
||||
padding: const EdgeInsets.all(WiseSpacing.x4),
|
||||
children: [
|
||||
Text('研报来源机构', style: Theme.of(context).textTheme.titleLarge),
|
||||
const SizedBox(height: WiseSpacing.x3),
|
||||
for (final item in items) ...[
|
||||
InstitutionCard(
|
||||
institution: item,
|
||||
onTap: () => openInstitutionDetail(context, widget.dataSource, item.id),
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x3),
|
||||
],
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class InstitutionCard extends StatelessWidget {
|
||||
const InstitutionCard({required this.institution, required this.onTap, super.key});
|
||||
|
||||
final Institution institution;
|
||||
final VoidCallback onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final initials = institution.nameCn.isEmpty ? '研' : institution.nameCn.characters.take(2).toString();
|
||||
return AppCard(
|
||||
onTap: onTap,
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 25,
|
||||
backgroundColor: WiseColors.secondary200,
|
||||
foregroundColor: WiseColors.primary,
|
||||
child: Text(initials, style: const TextStyle(fontWeight: FontWeight.w800)),
|
||||
),
|
||||
const SizedBox(width: WiseSpacing.x3),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(institution.nameCn, style: Theme.of(context).textTheme.titleMedium),
|
||||
if (institution.nameEn.isNotEmpty)
|
||||
Text(institution.nameEn, maxLines: 1, overflow: TextOverflow.ellipsis, style: Theme.of(context).textTheme.bodySmall),
|
||||
const SizedBox(height: WiseSpacing.x2),
|
||||
Wrap(
|
||||
spacing: WiseSpacing.x2,
|
||||
runSpacing: WiseSpacing.x2,
|
||||
children: [
|
||||
if (institution.institutionType.isNotEmpty) AppBadge(text: institution.institutionType),
|
||||
for (final topic in institution.coveredTopics.take(3)) AppBadge(text: topic, kind: BadgeKind.brand),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: WiseSpacing.x2),
|
||||
Column(
|
||||
children: [
|
||||
Text('${institution.reportCount}', style: Theme.of(context).textTheme.titleMedium?.copyWith(color: WiseColors.primary)),
|
||||
Text('份研报', style: Theme.of(context).textTheme.bodySmall),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../data/api/report_data_source.dart';
|
||||
import '../../data/models/models.dart';
|
||||
import '../../theme/wise_tokens.dart';
|
||||
import '../../widgets/app_card.dart';
|
||||
import '../../widgets/states.dart';
|
||||
|
||||
class ListenPage extends StatefulWidget {
|
||||
const ListenPage({required this.dataSource, required this.onPlay, super.key});
|
||||
|
||||
final ReportDataSource dataSource;
|
||||
final void Function(AudioItem item) onPlay;
|
||||
|
||||
@override
|
||||
State<ListenPage> createState() => _ListenPageState();
|
||||
}
|
||||
|
||||
class _ListenPageState extends State<ListenPage> {
|
||||
late Future<List<AudioItem>> future = widget.dataSource.listen();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder<List<AudioItem>>(
|
||||
future: future,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState != ConnectionState.done) return const LoadingState(label: '正在加载听单');
|
||||
if (snapshot.hasError) return ErrorState(message: snapshot.error.toString(), onRetry: () => setState(() => future = widget.dataSource.listen()));
|
||||
final items = snapshot.data ?? const [];
|
||||
if (items.isEmpty) return const EmptyState(title: '暂无音频研报', message: '先去研报页看看图文解读', icon: Icons.headphones_outlined);
|
||||
return ListView(
|
||||
padding: const EdgeInsets.all(WiseSpacing.x4),
|
||||
children: [
|
||||
Text('全站音频解读', style: Theme.of(context).textTheme.titleLarge),
|
||||
const SizedBox(height: WiseSpacing.x2),
|
||||
Text('游客可完整收听;真实音频流待后端接入。', style: Theme.of(context).textTheme.bodyMedium),
|
||||
const SizedBox(height: WiseSpacing.x4),
|
||||
for (final item in items) ...[
|
||||
AppCard(
|
||||
onTap: () => widget.onPlay(item),
|
||||
child: Row(
|
||||
children: [
|
||||
IconButton.filled(
|
||||
onPressed: () => widget.onPlay(item),
|
||||
icon: const Icon(Icons.play_arrow),
|
||||
style: IconButton.styleFrom(backgroundColor: WiseColors.primary, foregroundColor: Colors.white),
|
||||
),
|
||||
const SizedBox(width: WiseSpacing.x3),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(item.reportTitleCn, maxLines: 2, overflow: TextOverflow.ellipsis, style: Theme.of(context).textTheme.titleMedium),
|
||||
Text('${item.institution.nameCn} · ${formatDuration(item.durationSec)}', style: Theme.of(context).textTheme.bodySmall),
|
||||
const SizedBox(height: WiseSpacing.x2),
|
||||
LinearProgressIndicator(value: 0, minHeight: 4, color: WiseColors.accent, backgroundColor: WiseColors.border),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x3),
|
||||
],
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../data/api/report_data_source.dart';
|
||||
import '../../theme/wise_tokens.dart';
|
||||
import '../../widgets/app_buttons.dart';
|
||||
import '../../widgets/app_card.dart';
|
||||
import '../../widgets/sheets.dart';
|
||||
import '../../widgets/states.dart';
|
||||
|
||||
class ProfilePage extends StatelessWidget {
|
||||
const ProfilePage({required this.dataSource, super.key});
|
||||
|
||||
final ReportDataSource dataSource;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListView(
|
||||
padding: const EdgeInsets.all(WiseSpacing.x4),
|
||||
children: [
|
||||
AppCard(
|
||||
color: WiseColors.secondary200,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('游客', style: Theme.of(context).textTheme.headlineSmall),
|
||||
const SizedBox(height: WiseSpacing.x2),
|
||||
Text('浏览、阅读和完整收听不需要登录。收藏、历史同步和保存听单等待 auth 接口接入。', style: Theme.of(context).textTheme.bodyMedium),
|
||||
const SizedBox(height: WiseSpacing.x4),
|
||||
AppButton(
|
||||
label: '登录后保存个人状态',
|
||||
icon: Icons.login,
|
||||
onPressed: () => showLoginSheet(context),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x4),
|
||||
_ProfileRow(icon: Icons.favorite_border, title: '收藏研报', subtitle: '登录后同步收藏', onTap: () => showLoginSheet(context, reason: '登录后保存到你的收藏')),
|
||||
_ProfileRow(icon: Icons.history, title: '浏览历史', subtitle: '本地历史占位,服务端同步待接入', onTap: () => showAppToast(context, '历史同步接口待接入')),
|
||||
_ProfileRow(icon: Icons.playlist_add_check, title: '保存听单', subtitle: '登录后保存到你的听单', onTap: () => showLoginSheet(context, reason: '登录后保存到你的听单')),
|
||||
_ProfileRow(icon: Icons.open_in_new, title: '了解研值相关服务', subtitle: '外跳前提示风险边界', onTap: () => showOutboundSheet(context, title: '研值相关服务')),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ProfileRow extends StatelessWidget {
|
||||
const _ProfileRow({required this.icon, required this.title, required this.subtitle, required this.onTap});
|
||||
|
||||
final IconData icon;
|
||||
final String title;
|
||||
final String subtitle;
|
||||
final VoidCallback onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: WiseSpacing.x3),
|
||||
child: AppCard(
|
||||
onTap: onTap,
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(icon, color: WiseColors.primary),
|
||||
const SizedBox(width: WiseSpacing.x3),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(title, style: Theme.of(context).textTheme.titleMedium),
|
||||
Text(subtitle, style: Theme.of(context).textTheme.bodySmall),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Icon(Icons.chevron_right, color: WiseColors.textTertiary),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../data/api/report_data_source.dart';
|
||||
import '../../data/models/models.dart';
|
||||
import '../../routing/app_routes.dart';
|
||||
import '../../theme/wise_tokens.dart';
|
||||
import '../../widgets/app_buttons.dart';
|
||||
import '../../widgets/badges.dart';
|
||||
import '../../widgets/mini_player.dart';
|
||||
import '../../widgets/states.dart';
|
||||
import '../shared/report_card_widget.dart';
|
||||
|
||||
class ReportsPage extends StatefulWidget {
|
||||
const ReportsPage({
|
||||
required this.dataSource,
|
||||
required this.onPlay,
|
||||
this.player = const PlayerStateModel(),
|
||||
this.onStartModuleAudio,
|
||||
this.onToggleAudio,
|
||||
this.onSeekAudio,
|
||||
this.onSpeed,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final ReportDataSource dataSource;
|
||||
final void Function(AudioItem item) onPlay;
|
||||
final PlayerStateModel player;
|
||||
final void Function(String audioId, String reportId, String title, int durationSec)? onStartModuleAudio;
|
||||
final VoidCallback? onToggleAudio;
|
||||
final void Function(int delta)? onSeekAudio;
|
||||
final VoidCallback? onSpeed;
|
||||
|
||||
@override
|
||||
State<ReportsPage> createState() => _ReportsPageState();
|
||||
}
|
||||
|
||||
class _ReportsPageState extends State<ReportsPage> {
|
||||
late Future<List<ReportCardModel>> future = widget.dataSource.reports();
|
||||
String query = '';
|
||||
String topic = '';
|
||||
bool hasAudio = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder<List<ReportCardModel>>(
|
||||
future: future,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState != ConnectionState.done) return const LoadingState(label: '正在搜索研报');
|
||||
if (snapshot.hasError) return ErrorState(message: snapshot.error.toString(), onRetry: () => setState(() => future = widget.dataSource.reports()));
|
||||
final items = applyFilters(snapshot.data ?? const []);
|
||||
return ListView(
|
||||
padding: const EdgeInsets.all(WiseSpacing.x4),
|
||||
children: [
|
||||
TextField(
|
||||
decoration: InputDecoration(
|
||||
hintText: '搜索标题、机构或主题',
|
||||
prefixIcon: const Icon(Icons.search),
|
||||
suffixIcon: query.isEmpty ? null : IconButton(onPressed: () => setState(() => query = ''), icon: const Icon(Icons.close)),
|
||||
filled: true,
|
||||
fillColor: WiseColors.surface,
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(WiseRadius.pill), borderSide: BorderSide.none),
|
||||
),
|
||||
onChanged: (value) => setState(() => query = value.trim()),
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x3),
|
||||
Row(
|
||||
children: [
|
||||
AppButton(label: '筛选', icon: Icons.tune, kind: AppButtonKind.ghost, onPressed: openFilterSheet),
|
||||
const SizedBox(width: WiseSpacing.x2),
|
||||
AppChip(label: '有音频', selected: hasAudio, onTap: () => setState(() => hasAudio = !hasAudio)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x3),
|
||||
Text('共 ${items.length} 篇研报解读${query.isNotEmpty || topic.isNotEmpty || hasAudio ? '(已筛选)' : ''}', style: Theme.of(context).textTheme.bodySmall),
|
||||
const SizedBox(height: WiseSpacing.x3),
|
||||
if (items.isEmpty)
|
||||
EmptyState(
|
||||
title: query.isNotEmpty ? '未找到相关研报' : '当前筛选下暂无研报',
|
||||
message: query.isNotEmpty ? '换个关键词试试' : '调整筛选条件后再试',
|
||||
actionLabel: '清除筛选',
|
||||
onAction: () => setState(() {
|
||||
query = '';
|
||||
topic = '';
|
||||
hasAudio = false;
|
||||
}),
|
||||
)
|
||||
else
|
||||
for (final report in items) ...[
|
||||
ReportCardWidget(
|
||||
report: report,
|
||||
onTap: () => openReportDetail(
|
||||
context,
|
||||
widget.dataSource,
|
||||
report,
|
||||
player: widget.player,
|
||||
onStartAudio: widget.onStartModuleAudio,
|
||||
onToggleAudio: widget.onToggleAudio,
|
||||
onSeekAudio: widget.onSeekAudio,
|
||||
onSpeed: widget.onSpeed,
|
||||
),
|
||||
onPlayTap: () => widget.onPlay(AudioItem(audioId: 'local_${report.id}', reportId: report.id, titleCn: report.titleCn, reportTitleCn: report.titleCn, durationSec: 180, institution: report.institution)),
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x3),
|
||||
],
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
List<ReportCardModel> applyFilters(List<ReportCardModel> items) {
|
||||
return items.where((item) {
|
||||
final hay = '${item.titleCn} ${item.institution.nameCn} ${item.topics.join(' ')}'.toLowerCase();
|
||||
if (query.isNotEmpty && !hay.contains(query.toLowerCase())) return false;
|
||||
if (topic.isNotEmpty && !item.topics.contains(topic)) return false;
|
||||
if (hasAudio && !item.hasAudio) return false;
|
||||
return true;
|
||||
}).toList();
|
||||
}
|
||||
|
||||
void openFilterSheet() {
|
||||
widget.dataSource.reports().then((items) {
|
||||
if (!mounted) return;
|
||||
final topics = {for (final item in items) ...item.topics}.toList();
|
||||
showModalBottomSheet<void>(
|
||||
context: context,
|
||||
showDragHandle: true,
|
||||
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.vertical(top: Radius.circular(WiseRadius.lg))),
|
||||
builder: (context) => Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 4, 20, 28),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('筛选研报', style: Theme.of(context).textTheme.titleLarge),
|
||||
const SizedBox(height: WiseSpacing.x3),
|
||||
Wrap(
|
||||
spacing: WiseSpacing.x2,
|
||||
runSpacing: WiseSpacing.x2,
|
||||
children: [
|
||||
AppChip(label: '全部主题', selected: topic.isEmpty, onTap: () => selectTopic('')),
|
||||
for (final t in topics) AppChip(label: t, selected: topic == t, onTap: () => selectTopic(t)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x4),
|
||||
AppButton(label: '完成', expand: true, onPressed: () => Navigator.pop(context)),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void selectTopic(String value) {
|
||||
setState(() => topic = value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../data/models/models.dart';
|
||||
import '../../theme/wise_tokens.dart';
|
||||
import '../../widgets/app_card.dart';
|
||||
import '../../widgets/badges.dart';
|
||||
|
||||
class ReportCardWidget extends StatelessWidget {
|
||||
const ReportCardWidget({
|
||||
required this.report,
|
||||
required this.onTap,
|
||||
this.hero = false,
|
||||
this.onInstitutionTap,
|
||||
this.onPlayTap,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final ReportCardModel report;
|
||||
final VoidCallback onTap;
|
||||
final bool hero;
|
||||
final VoidCallback? onInstitutionTap;
|
||||
final VoidCallback? onPlayTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final child = Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Wrap(
|
||||
spacing: WiseSpacing.x2,
|
||||
runSpacing: WiseSpacing.x2,
|
||||
children: [
|
||||
AppBadge(text: report.interpretationLabel, kind: BadgeKind.brand),
|
||||
if (report.hasAudio)
|
||||
const AppBadge(text: '音频', icon: Icons.graphic_eq, kind: BadgeKind.audio),
|
||||
if (report.sourceTier.isNotEmpty)
|
||||
AppBadge(text: report.sourceTier, icon: Icons.verified_outlined, kind: BadgeKind.tier),
|
||||
for (final topic in report.topics.take(3)) AppBadge(text: topic),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x3),
|
||||
Text(
|
||||
report.titleCn,
|
||||
maxLines: hero ? 3 : 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: hero
|
||||
? Theme.of(context).textTheme.titleLarge
|
||||
: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
if (report.oneLiner.isNotEmpty) ...[
|
||||
const SizedBox(height: WiseSpacing.x2),
|
||||
Text(
|
||||
report.oneLiner,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
],
|
||||
const SizedBox(height: WiseSpacing.x3),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: InkWell(
|
||||
onTap: onInstitutionTap,
|
||||
child: Text(
|
||||
'${report.institution.nameCn}${report.releasedAt == null ? '' : ' · ${formatDate(report.releasedAt)}'}',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (report.hasAudio)
|
||||
TextButton.icon(
|
||||
onPressed: onPlayTap,
|
||||
icon: const Icon(Icons.play_circle_outline, size: 18),
|
||||
label: const Text('听研报'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
return hero
|
||||
? HeroReportCard(onTap: onTap, child: child)
|
||||
: AppCard(onTap: onTap, child: child);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../data/api/report_data_source.dart';
|
||||
import '../data/models/models.dart';
|
||||
import '../theme/wise_tokens.dart';
|
||||
import '../widgets/mini_player.dart';
|
||||
import 'feed/feed_page.dart';
|
||||
import 'institutions/institutions_page.dart';
|
||||
import 'listen/listen_page.dart';
|
||||
import 'profile/profile_page.dart';
|
||||
import 'reports/reports_page.dart';
|
||||
|
||||
class ShellPage extends StatefulWidget {
|
||||
const ShellPage({required this.dataSource, super.key});
|
||||
|
||||
final ReportDataSource dataSource;
|
||||
|
||||
@override
|
||||
State<ShellPage> createState() => _ShellPageState();
|
||||
}
|
||||
|
||||
class _ShellPageState extends State<ShellPage> {
|
||||
int index = 0;
|
||||
PlayerStateModel player = const PlayerStateModel();
|
||||
Timer? timer;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
timer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void startAudio(AudioItem item) {
|
||||
timer?.cancel();
|
||||
setState(() {
|
||||
player = PlayerStateModel(
|
||||
audioId: item.audioId,
|
||||
reportId: item.reportId,
|
||||
title: item.titleCn,
|
||||
durationSec: item.durationSec,
|
||||
playing: true,
|
||||
speed: player.speed,
|
||||
);
|
||||
});
|
||||
timer = Timer.periodic(const Duration(seconds: 1), (_) => tick());
|
||||
}
|
||||
|
||||
void startModuleAudio(String audioId, String reportId, String title, int durationSec) {
|
||||
startAudio(
|
||||
AudioItem(
|
||||
audioId: audioId,
|
||||
reportId: reportId,
|
||||
titleCn: title,
|
||||
reportTitleCn: title,
|
||||
durationSec: durationSec,
|
||||
institution: const Institution(id: '', nameCn: ''),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void tick() {
|
||||
if (!player.playing) return;
|
||||
final next = player.positionSec + player.speed.round().clamp(1, 2);
|
||||
setState(() {
|
||||
player = player.copyWith(
|
||||
positionSec: next >= player.durationSec ? player.durationSec : next,
|
||||
playing: next < player.durationSec,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void toggleAudio() {
|
||||
if (!player.hasAudio) return;
|
||||
setState(() => player = player.copyWith(playing: !player.playing));
|
||||
}
|
||||
|
||||
void seekAudio(int delta) {
|
||||
if (!player.hasAudio) return;
|
||||
setState(() {
|
||||
player = player.copyWith(
|
||||
positionSec: (player.positionSec + delta).clamp(0, player.durationSec),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void cycleSpeed() {
|
||||
const speeds = [1.0, 1.25, 1.5, 2.0];
|
||||
final current = speeds.indexOf(player.speed);
|
||||
setState(() => player = player.copyWith(speed: speeds[(current + 1) % speeds.length]));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final pages = [
|
||||
FeedPage(
|
||||
dataSource: widget.dataSource,
|
||||
onPlay: startAudio,
|
||||
player: player,
|
||||
onStartModuleAudio: startModuleAudio,
|
||||
onToggleAudio: toggleAudio,
|
||||
onSeekAudio: seekAudio,
|
||||
onSpeed: cycleSpeed,
|
||||
),
|
||||
ReportsPage(
|
||||
dataSource: widget.dataSource,
|
||||
onPlay: startAudio,
|
||||
player: player,
|
||||
onStartModuleAudio: startModuleAudio,
|
||||
onToggleAudio: toggleAudio,
|
||||
onSeekAudio: seekAudio,
|
||||
onSpeed: cycleSpeed,
|
||||
),
|
||||
InstitutionsPage(dataSource: widget.dataSource),
|
||||
ListenPage(dataSource: widget.dataSource, onPlay: startAudio),
|
||||
ProfilePage(dataSource: widget.dataSource),
|
||||
];
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('研听'),
|
||||
Text(
|
||||
'全球机构研报中文解读',
|
||||
style: TextStyle(fontSize: 12, color: WiseColors.textSecondary, fontWeight: FontWeight.w500),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
body: pages[index],
|
||||
bottomNavigationBar: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
MiniPlayer(player: player, onToggle: toggleAudio),
|
||||
NavigationBar(
|
||||
selectedIndex: index,
|
||||
onDestinationSelected: (value) => setState(() => index = value),
|
||||
destinations: const [
|
||||
NavigationDestination(icon: Icon(Icons.auto_awesome_outlined), selectedIcon: Icon(Icons.auto_awesome), label: '推荐'),
|
||||
NavigationDestination(icon: Icon(Icons.article_outlined), selectedIcon: Icon(Icons.article), label: '研报'),
|
||||
NavigationDestination(icon: Icon(Icons.account_balance_outlined), selectedIcon: Icon(Icons.account_balance), label: '机构'),
|
||||
NavigationDestination(icon: Icon(Icons.headphones_outlined), selectedIcon: Icon(Icons.headphones), label: '听单'),
|
||||
NavigationDestination(icon: Icon(Icons.person_outline), selectedIcon: Icon(Icons.person), label: '我的'),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user