|
|
@@ -3,27 +3,39 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
import 'package:keyboard/resource/string.gen.dart';
|
|
|
import 'package:lottie/lottie.dart';
|
|
|
|
|
|
+import '../../../data/api/response/intimacy_analyze_response.dart';
|
|
|
+import '../../../data/bean/intimacy_analyse_report.dart';
|
|
|
import '../../../resource/assets.gen.dart';
|
|
|
import '../../../resource/colors.gen.dart';
|
|
|
+import '../../../utils/string_format_util.dart';
|
|
|
import '../../../widget/animated_progress_bar.dart';
|
|
|
import '../../../widget/markdown/markdown_viewer.dart';
|
|
|
+import '../analyse_report/widget/report_item_widget.dart';
|
|
|
|
|
|
/// 亲密度报告组件
|
|
|
class IntimacyAnalyseReportWidget extends StatelessWidget {
|
|
|
- /// 报告内容
|
|
|
+ /// 报告内容,Markdown格式
|
|
|
final String reportContent;
|
|
|
|
|
|
+ /// 分析结果
|
|
|
+ final IntimacyAnalyzeResponse? intimacyAnalyzeResult;
|
|
|
+
|
|
|
/// 是否已解锁
|
|
|
final bool unlock;
|
|
|
|
|
|
/// 是否是预览
|
|
|
final bool isPreview;
|
|
|
|
|
|
+ /// 是否报告生成中
|
|
|
+ final bool isReportCreating;
|
|
|
+
|
|
|
const IntimacyAnalyseReportWidget({
|
|
|
super.key,
|
|
|
- required this.reportContent,
|
|
|
+ this.reportContent = '',
|
|
|
+ this.intimacyAnalyzeResult,
|
|
|
this.unlock = false,
|
|
|
this.isPreview = false,
|
|
|
+ this.isReportCreating = false,
|
|
|
});
|
|
|
|
|
|
@override
|
|
|
@@ -35,11 +47,15 @@ class IntimacyAnalyseReportWidget extends StatelessWidget {
|
|
|
if (!unlock) {
|
|
|
return UnlockReportCardWidget();
|
|
|
}
|
|
|
- return reportContent.isEmpty
|
|
|
- // 报告生成中
|
|
|
- ? CreatingReportCardWidget()
|
|
|
- // 已出报告
|
|
|
- : ExistReportCardWidget(reportContent: reportContent);
|
|
|
+ // 报告生成中
|
|
|
+ if (isReportCreating) {
|
|
|
+ return CreatingReportCardWidget();
|
|
|
+ }
|
|
|
+ // 已出报告
|
|
|
+ return ExistReportCardWidget(
|
|
|
+ reportContent: reportContent,
|
|
|
+ intimacyAnalyzeResult: intimacyAnalyzeResult,
|
|
|
+ );
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -86,7 +102,14 @@ class ExistReportCardWidget extends StatelessWidget {
|
|
|
/// 报告内容,Markdown格式
|
|
|
final String reportContent;
|
|
|
|
|
|
- const ExistReportCardWidget({super.key, required this.reportContent});
|
|
|
+ /// 分析结果
|
|
|
+ final IntimacyAnalyzeResponse? intimacyAnalyzeResult;
|
|
|
+
|
|
|
+ const ExistReportCardWidget({
|
|
|
+ super.key,
|
|
|
+ required this.reportContent,
|
|
|
+ this.intimacyAnalyzeResult,
|
|
|
+ });
|
|
|
|
|
|
@override
|
|
|
Widget build(BuildContext context) {
|
|
|
@@ -96,7 +119,9 @@ class ExistReportCardWidget extends StatelessWidget {
|
|
|
children: [
|
|
|
_buildReportOverview(),
|
|
|
SizedBox(height: 10.h),
|
|
|
- _buildReportDetail(),
|
|
|
+ reportContent.isNotEmpty
|
|
|
+ ? _buildReportDetailByMarkdown()
|
|
|
+ : _buildReportDetail(),
|
|
|
],
|
|
|
),
|
|
|
);
|
|
|
@@ -104,6 +129,12 @@ class ExistReportCardWidget extends StatelessWidget {
|
|
|
|
|
|
/// 报告概览,包含概览数值和图表
|
|
|
Widget _buildReportOverview() {
|
|
|
+ if (intimacyAnalyzeResult == null) {
|
|
|
+ return SizedBox();
|
|
|
+ }
|
|
|
+
|
|
|
+ var analyzeResult = intimacyAnalyzeResult!;
|
|
|
+
|
|
|
// 圆角背景
|
|
|
return Container(
|
|
|
padding: EdgeInsets.only(left: 12.w, right: 12.w, top: 12.h),
|
|
|
@@ -123,15 +154,21 @@ class ExistReportCardWidget extends StatelessWidget {
|
|
|
),
|
|
|
child: Row(
|
|
|
children: [
|
|
|
- _buildIntimacyOverviewItem("30"),
|
|
|
+ _buildIntimacyOverviewItem(
|
|
|
+ StringFormatUtil.removePercentSymbol(
|
|
|
+ analyzeResult.emotion ?? "",
|
|
|
+ ),
|
|
|
+ ),
|
|
|
_buildOverviewDivider(),
|
|
|
- _buildCurrentStageOverviewItem("相互了解"),
|
|
|
+ _buildCurrentStageOverviewItem(
|
|
|
+ analyzeResult.intimacyPhase ?? "",
|
|
|
+ ),
|
|
|
],
|
|
|
),
|
|
|
),
|
|
|
SizedBox(height: 36.h),
|
|
|
// 图表
|
|
|
- _buildChart(),
|
|
|
+ _buildChart(analyzeResult),
|
|
|
],
|
|
|
),
|
|
|
);
|
|
|
@@ -244,29 +281,48 @@ class ExistReportCardWidget extends StatelessWidget {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ /// 将百分比转换为进度条需要的数值
|
|
|
+ double _convertPercentValue2ProgressBar(String percentValue) {
|
|
|
+ if (percentValue.isEmpty) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ // 去掉%号后的数值
|
|
|
+ String valueStr = StringFormatUtil.removePercentSymbol(percentValue);
|
|
|
+ double noPercentValue = double.tryParse(valueStr) ?? 0;
|
|
|
+ if (noPercentValue == 0) {
|
|
|
+ return 0;
|
|
|
+ } else {
|
|
|
+ // 除以100,转换为0-1之间的数值,才是进度条需要的数值
|
|
|
+ double progressValue = noPercentValue / 100;
|
|
|
+ return progressValue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/// 报告图表
|
|
|
- Widget _buildChart() {
|
|
|
+ Widget _buildChart(IntimacyAnalyzeResponse analyzeResult) {
|
|
|
return Column(
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
children: [
|
|
|
_buildValueItem(
|
|
|
iconProvider: Assets.images.iconEmojiLike.provider(),
|
|
|
- title: "互动好感度",
|
|
|
- value: 0.5,
|
|
|
+ title: StringName.intimacyInteraction,
|
|
|
+ value: _convertPercentValue2ProgressBar(
|
|
|
+ analyzeResult.interaction ?? "",
|
|
|
+ ),
|
|
|
progressColors: [ColorName.blueGradient1, ColorName.blueGradient2],
|
|
|
),
|
|
|
SizedBox(height: 18.h),
|
|
|
_buildValueItem(
|
|
|
iconProvider: Assets.images.iconEmojiChat.provider(),
|
|
|
- title: "话题好感度",
|
|
|
- value: 0.35,
|
|
|
+ title: StringName.intimacyTopic,
|
|
|
+ value: _convertPercentValue2ProgressBar(analyzeResult.topic ?? ""),
|
|
|
progressColors: [ColorName.greenGradient1, ColorName.greenGradient2],
|
|
|
),
|
|
|
SizedBox(height: 18.h),
|
|
|
_buildValueItem(
|
|
|
iconProvider: Assets.images.iconEmojiLike.provider(),
|
|
|
- title: "情绪回应",
|
|
|
- value: 1.0,
|
|
|
+ title: StringName.intimacyRespond,
|
|
|
+ value: _convertPercentValue2ProgressBar(analyzeResult.respond ?? ""),
|
|
|
progressColors: [
|
|
|
ColorName.yellowGradient1,
|
|
|
ColorName.yellowGradient2,
|
|
|
@@ -275,15 +331,19 @@ class ExistReportCardWidget extends StatelessWidget {
|
|
|
SizedBox(height: 18.h),
|
|
|
_buildValueItem(
|
|
|
iconProvider: Assets.images.iconEmojiPercent.provider(),
|
|
|
- title: "亲密词占比",
|
|
|
- value: 0.4,
|
|
|
+ title: StringName.intimacyintimacyRatio,
|
|
|
+ value: _convertPercentValue2ProgressBar(
|
|
|
+ analyzeResult.intimacyRatio ?? "",
|
|
|
+ ),
|
|
|
progressColors: [ColorName.pinkGradient1, ColorName.pinkGradient2],
|
|
|
),
|
|
|
SizedBox(height: 18.h),
|
|
|
_buildValueItem(
|
|
|
iconProvider: Assets.images.iconEmojiLove.provider(),
|
|
|
- title: "缘分指数",
|
|
|
- value: 0.15,
|
|
|
+ title: analyzeResult.directionName ?? "",
|
|
|
+ value: _convertPercentValue2ProgressBar(
|
|
|
+ analyzeResult.direction ?? "",
|
|
|
+ ),
|
|
|
progressColors: [
|
|
|
ColorName.purpleGradient1,
|
|
|
ColorName.purpleGradient2,
|
|
|
@@ -345,8 +405,8 @@ class ExistReportCardWidget extends StatelessWidget {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- /// 报告详情
|
|
|
- Widget _buildReportDetail() {
|
|
|
+ /// 报告详情,使用Markdown
|
|
|
+ Widget _buildReportDetailByMarkdown() {
|
|
|
return Container(
|
|
|
decoration: ShapeDecoration(
|
|
|
color: ColorName.white,
|
|
|
@@ -362,6 +422,54 @@ class ExistReportCardWidget extends StatelessWidget {
|
|
|
),
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
+ /// 报告详情,使用组件渲染
|
|
|
+ Widget _buildReportDetail() {
|
|
|
+ if (intimacyAnalyzeResult == null) {
|
|
|
+ return SizedBox();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 组装数据
|
|
|
+ IntimacyAnalyseReport reportPreviewData = IntimacyAnalyseReport(
|
|
|
+ list: [
|
|
|
+ AnalyseItem(
|
|
|
+ title: StringName.intimacyintimacyEmotionNeed,
|
|
|
+ sections: [intimacyAnalyzeResult?.need ?? ""],
|
|
|
+ ),
|
|
|
+ AnalyseItem(
|
|
|
+ title: StringName.intimacyintimacyChatStrategy,
|
|
|
+ sections: [intimacyAnalyzeResult?.chatStrategy ?? ""],
|
|
|
+ ),
|
|
|
+ AnalyseItem(
|
|
|
+ title: StringName.intimacyintimacySummary,
|
|
|
+ sections: [intimacyAnalyzeResult?.summary ?? ""],
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ );
|
|
|
+
|
|
|
+ return _buildReportContent(reportPreviewData);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 构建报告内容
|
|
|
+ Widget _buildReportContent(IntimacyAnalyseReport report) {
|
|
|
+ return Container(
|
|
|
+ padding: EdgeInsets.all(14.w),
|
|
|
+ decoration: ShapeDecoration(
|
|
|
+ color: ColorName.white,
|
|
|
+ shape: RoundedRectangleBorder(
|
|
|
+ borderRadius: BorderRadius.circular(30.r),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ child: Column(
|
|
|
+ children: [
|
|
|
+ // 报告列表
|
|
|
+ ...report.list.map((ele) {
|
|
|
+ return ReportItemWidget(item: ele);
|
|
|
+ }),
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/// 报告生成中的卡片
|