fix: repair record processing logic

This commit is contained in:
Nedifinita
2025-09-25 22:25:51 +08:00
parent bf850eed38
commit 72f9dfe17b
3 changed files with 49 additions and 51 deletions

View File

@@ -149,7 +149,7 @@ class TrainRecord {
final lbjClassValue = lbjClass.trim(); final lbjClassValue = lbjClass.trim();
final trainValue = train.trim(); final trainValue = train.trim();
if (trainValue == "<NUL>") { if (trainValue == "<NUL>" || trainValue.contains("-----")) {
return ""; return "";
} }

View File

@@ -580,17 +580,7 @@ class HistoryScreenState extends State<HistoryScreen> {
_buildRecordHeader(record), _buildRecordHeader(record),
_buildPositionAndSpeed(record), _buildPositionAndSpeed(record),
_buildLocoInfo(record), _buildLocoInfo(record),
AnimatedCrossFade( if (isExpanded) _buildExpandedContent(record),
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,
)
])))); ]))));
WidgetsBinding.instance.addPostFrameCallback((_) { WidgetsBinding.instance.addPostFrameCallback((_) {
@@ -623,7 +613,7 @@ class HistoryScreenState extends State<HistoryScreen> {
formattedLocoInfo = record.loco; formattedLocoInfo = record.loco;
} }
if (record.fullTrainNumber.isEmpty) { if (record.fullTrainNumber.isEmpty && formattedLocoInfo.isEmpty) {
return Text( return Text(
(record.time == "<NUL>" || record.time.isEmpty) (record.time == "<NUL>" || record.time.isEmpty)
? record.receivedTimestamp.toString().split(".")[0] ? record.receivedTimestamp.toString().split(".")[0]
@@ -632,6 +622,11 @@ class HistoryScreenState extends State<HistoryScreen> {
overflow: TextOverflow.ellipsis); overflow: TextOverflow.ellipsis);
} }
final hasTrainNumber = record.fullTrainNumber.isNotEmpty;
final hasDirection = record.direction == 1 || record.direction == 3;
final hasLocoInfo = formattedLocoInfo.isNotEmpty && formattedLocoInfo != "<NUL>";
final shouldShowTrainRow = hasTrainNumber || hasDirection || hasLocoInfo;
return Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ return Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
Flexible( Flexible(
@@ -647,43 +642,46 @@ class HistoryScreenState extends State<HistoryScreen> {
style: const TextStyle(fontSize: 11, color: Colors.grey), style: const TextStyle(fontSize: 11, color: Colors.grey),
overflow: TextOverflow.ellipsis)) overflow: TextOverflow.ellipsis))
]), ]),
const SizedBox(height: 2), if (shouldShowTrainRow) ...[
Row( const SizedBox(height: 2),
mainAxisAlignment: MainAxisAlignment.spaceBetween, Row(
crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ crossAxisAlignment: CrossAxisAlignment.center,
Flexible( children: [
child: Row( Flexible(
mainAxisSize: MainAxisSize.min, child: Row(
crossAxisAlignment: CrossAxisAlignment.center, mainAxisSize: MainAxisSize.min,
children: [ crossAxisAlignment: CrossAxisAlignment.center,
Flexible( children: [
child: Text(record.fullTrainNumber, if (hasTrainNumber)
style: const TextStyle( Flexible(
fontSize: 20, child: Text(record.fullTrainNumber,
fontWeight: FontWeight.bold, style: const TextStyle(
color: Colors.white), fontSize: 20,
overflow: TextOverflow.ellipsis)), fontWeight: FontWeight.bold,
const SizedBox(width: 6), color: Colors.white),
if (record.direction == 1 || record.direction == 3) overflow: TextOverflow.ellipsis)),
Container( if (hasTrainNumber && hasDirection) const SizedBox(width: 6),
width: 20, if (hasDirection)
height: 20, Container(
decoration: BoxDecoration( width: 20,
color: Colors.white, height: 20,
borderRadius: BorderRadius.circular(2)), decoration: BoxDecoration(
child: Center( color: Colors.white,
child: Text(record.direction == 1 ? "" : "", borderRadius: BorderRadius.circular(2)),
style: const TextStyle( child: Center(
fontSize: 12, child: Text(record.direction == 1 ? "" : "",
fontWeight: FontWeight.bold, style: const TextStyle(
color: Colors.black)))) fontSize: 12,
])), fontWeight: FontWeight.bold,
if (formattedLocoInfo.isNotEmpty && formattedLocoInfo != "<NUL>") color: Colors.black))))
Text(formattedLocoInfo, ])),
style: const TextStyle(fontSize: 14, color: Colors.white70)) if (hasLocoInfo)
]), Text(formattedLocoInfo,
const SizedBox(height: 2) style: const TextStyle(fontSize: 14, color: Colors.white70))
]),
const SizedBox(height: 2)
]
]); ]);
} }

View File

@@ -5,7 +5,7 @@ class MergeService {
static String? _generateGroupKey(TrainRecord record, GroupBy groupBy) { static String? _generateGroupKey(TrainRecord record, GroupBy groupBy) {
final train = record.train.trim(); final train = record.train.trim();
final loco = record.loco.trim(); final loco = record.loco.trim();
final hasTrain = train.isNotEmpty && train != "<NUL>"; final hasTrain = train.isNotEmpty && train != "<NUL>" && !train.contains("-----");
final hasLoco = loco.isNotEmpty && loco != "<NUL>"; final hasLoco = loco.isNotEmpty && loco != "<NUL>";
switch (groupBy) { switch (groupBy) {