From 72f9dfe17b3189d41815475513ae750847e9fb65 Mon Sep 17 00:00:00 2001 From: Nedifinita Date: Thu, 25 Sep 2025 22:25:51 +0800 Subject: [PATCH] fix: repair record processing logic --- lib/models/train_record.dart | 2 +- lib/screens/history_screen.dart | 96 ++++++++++++++++----------------- lib/services/merge_service.dart | 2 +- 3 files changed, 49 insertions(+), 51 deletions(-) diff --git a/lib/models/train_record.dart b/lib/models/train_record.dart index ed971b6..ed478bb 100644 --- a/lib/models/train_record.dart +++ b/lib/models/train_record.dart @@ -149,7 +149,7 @@ class TrainRecord { final lbjClassValue = lbjClass.trim(); final trainValue = train.trim(); - if (trainValue == "") { + if (trainValue == "" || trainValue.contains("-----")) { return ""; } diff --git a/lib/screens/history_screen.dart b/lib/screens/history_screen.dart index 11d49fb..f7acb1d 100644 --- a/lib/screens/history_screen.dart +++ b/lib/screens/history_screen.dart @@ -580,17 +580,7 @@ class HistoryScreenState extends State { _buildRecordHeader(record), _buildPositionAndSpeed(record), _buildLocoInfo(record), - AnimatedCrossFade( - duration: const Duration(milliseconds: 300), - firstChild: const SizedBox.shrink(), - secondChild: _buildExpandedContent(record), - crossFadeState: isExpanded - ? CrossFadeState.showSecond - : CrossFadeState.showFirst, - firstCurve: Curves.easeInOut, - secondCurve: Curves.easeInOut, - sizeCurve: Curves.easeInOut, - ) + if (isExpanded) _buildExpandedContent(record), ])))); WidgetsBinding.instance.addPostFrameCallback((_) { @@ -623,7 +613,7 @@ class HistoryScreenState extends State { formattedLocoInfo = record.loco; } - if (record.fullTrainNumber.isEmpty) { + if (record.fullTrainNumber.isEmpty && formattedLocoInfo.isEmpty) { return Text( (record.time == "" || record.time.isEmpty) ? record.receivedTimestamp.toString().split(".")[0] @@ -632,6 +622,11 @@ class HistoryScreenState extends State { overflow: TextOverflow.ellipsis); } + final hasTrainNumber = record.fullTrainNumber.isNotEmpty; + final hasDirection = record.direction == 1 || record.direction == 3; + final hasLocoInfo = formattedLocoInfo.isNotEmpty && formattedLocoInfo != ""; + final shouldShowTrainRow = hasTrainNumber || hasDirection || hasLocoInfo; + return Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Flexible( @@ -647,43 +642,46 @@ class HistoryScreenState extends State { style: const TextStyle(fontSize: 11, color: Colors.grey), overflow: TextOverflow.ellipsis)) ]), - const SizedBox(height: 2), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Flexible( - child: Row( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Flexible( - child: Text(record.fullTrainNumber, - style: const TextStyle( - fontSize: 20, - fontWeight: FontWeight.bold, - color: Colors.white), - overflow: TextOverflow.ellipsis)), - const SizedBox(width: 6), - if (record.direction == 1 || record.direction == 3) - Container( - width: 20, - height: 20, - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(2)), - child: Center( - child: Text(record.direction == 1 ? "下" : "上", - style: const TextStyle( - fontSize: 12, - fontWeight: FontWeight.bold, - color: Colors.black)))) - ])), - if (formattedLocoInfo.isNotEmpty && formattedLocoInfo != "") - Text(formattedLocoInfo, - style: const TextStyle(fontSize: 14, color: Colors.white70)) - ]), - const SizedBox(height: 2) + if (shouldShowTrainRow) ...[ + const SizedBox(height: 2), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Flexible( + child: Row( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + if (hasTrainNumber) + Flexible( + child: Text(record.fullTrainNumber, + style: const TextStyle( + fontSize: 20, + fontWeight: FontWeight.bold, + color: Colors.white), + overflow: TextOverflow.ellipsis)), + if (hasTrainNumber && hasDirection) const SizedBox(width: 6), + if (hasDirection) + Container( + width: 20, + height: 20, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(2)), + child: Center( + child: Text(record.direction == 1 ? "下" : "上", + style: const TextStyle( + fontSize: 12, + fontWeight: FontWeight.bold, + color: Colors.black)))) + ])), + if (hasLocoInfo) + Text(formattedLocoInfo, + style: const TextStyle(fontSize: 14, color: Colors.white70)) + ]), + const SizedBox(height: 2) + ] ]); } diff --git a/lib/services/merge_service.dart b/lib/services/merge_service.dart index 642a075..8665e01 100644 --- a/lib/services/merge_service.dart +++ b/lib/services/merge_service.dart @@ -5,7 +5,7 @@ class MergeService { static String? _generateGroupKey(TrainRecord record, GroupBy groupBy) { final train = record.train.trim(); final loco = record.loco.trim(); - final hasTrain = train.isNotEmpty && train != ""; + final hasTrain = train.isNotEmpty && train != "" && !train.contains("-----"); final hasLoco = loco.isNotEmpty && loco != ""; switch (groupBy) {