|
|
@@ -3,16 +3,21 @@ 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 '../../../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';
|
|
|
|
|
|
/// 亲密度报告组件
|
|
|
class IntimacyAnalyseReportWidget extends StatelessWidget {
|
|
|
- /// 报告内容
|
|
|
+ /// 报告内容,Markdown格式
|
|
|
final String reportContent;
|
|
|
|
|
|
+ /// 分析结果
|
|
|
+ final IntimacyAnalyzeResponse? intimacyAnalyzeResult;
|
|
|
+
|
|
|
/// 是否已解锁
|
|
|
final bool unlock;
|
|
|
|
|
|
@@ -22,6 +27,7 @@ class IntimacyAnalyseReportWidget extends StatelessWidget {
|
|
|
const IntimacyAnalyseReportWidget({
|
|
|
super.key,
|
|
|
required this.reportContent,
|
|
|
+ this.intimacyAnalyzeResult,
|
|
|
this.unlock = false,
|
|
|
this.isPreview = false,
|
|
|
});
|
|
|
@@ -35,11 +41,15 @@ class IntimacyAnalyseReportWidget extends StatelessWidget {
|
|
|
if (!unlock) {
|
|
|
return UnlockReportCardWidget();
|
|
|
}
|
|
|
- return reportContent.isEmpty
|
|
|
- // 报告生成中
|
|
|
- ? CreatingReportCardWidget()
|
|
|
- // 已出报告
|
|
|
- : ExistReportCardWidget(reportContent: reportContent);
|
|
|
+ // 报告生成中
|
|
|
+ if (intimacyAnalyzeResult == null || reportContent.isEmpty) {
|
|
|
+ return CreatingReportCardWidget();
|
|
|
+ }
|
|
|
+ // 已出报告
|
|
|
+ return ExistReportCardWidget(
|
|
|
+ reportContent: reportContent,
|
|
|
+ intimacyAnalyzeResult: intimacyAnalyzeResult,
|
|
|
+ );
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -86,7 +96,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) {
|
|
|
@@ -104,6 +121,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 +146,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 +273,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 +323,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,
|