From a5e1e36ebf4447d07b9f7b5ebbd7fe00bc99621e Mon Sep 17 00:00:00 2001 From: kfj001 Date: Sun, 10 May 2026 00:45:31 +0000 Subject: [PATCH] Fixes time display of current/next song UI. Adds localized formatting code for start times of shows current and next. --- lib/show_card.dart | 2 +- lib/time_formatter.dart | 38 +++++++++++++++++++++++++++++++------- lib/track_card.dart | 6 +++--- pubspec.yaml | 1 + 4 files changed, 36 insertions(+), 11 deletions(-) diff --git a/lib/show_card.dart b/lib/show_card.dart index f516e3f..1d69104 100644 --- a/lib/show_card.dart +++ b/lib/show_card.dart @@ -40,7 +40,7 @@ class ShowCard extends StatelessWidget { ), const SizedBox(width: 8), Text( - formatTimeWindow(show?.starts, show?.ends), + formatStartingTime(show?.starts), style: Theme.of(context).textTheme.labelSmall, ), ], diff --git a/lib/time_formatter.dart b/lib/time_formatter.dart index 3ca5bb3..72c4c9a 100644 --- a/lib/time_formatter.dart +++ b/lib/time_formatter.dart @@ -1,11 +1,35 @@ -String formatTimeWindow(String? starts, String? ends) { - String formatOne(String? value) { - if (value == null || value.length < 16) { - return '--:--'; - } +import 'package:flutter/material.dart'; +import 'package:intl/intl.dart'; - return value.substring(11, 16); +// Source - https://stackoverflow.com/a/54775297 +// Posted by diegoveloper, modified by community. See post 'Timeline' for change history +// Retrieved 2026-05-09, License - CC BY-SA 4.0 + +String _printDuration(Duration duration) { + String negativeSign = duration.isNegative ? '-' : ''; + String twoDigits(int n) => n.toString().padLeft(2, "0"); + String twoDigitMinutes = twoDigits(duration.inMinutes.remainder(60).abs()); + String twoDigitSeconds = twoDigits(duration.inSeconds.remainder(60).abs()); + return "$negativeSign$twoDigitMinutes:$twoDigitSeconds"; +} + +String formatTimeWindow(String? starts, String? ends) { + if (starts != null && ends != null) { + DateTime startDt = DateTime.parse(starts); + DateTime endDt = DateTime.parse(ends); + + Duration songLength = endDt.difference(startDt); + + return _printDuration(songLength); } - return '${formatOne(starts)} - ${formatOne(ends)}'; + return "--:--"; +} + +String formatStartingTime(String? startingTime) { + if (startingTime != null) { + DateTime dtStartTime = DateTime.parse(startingTime); + return DateFormat('jm').format(dtStartTime); + } + return "--:--"; } diff --git a/lib/track_card.dart b/lib/track_card.dart index e0376f0..81ad1d7 100644 --- a/lib/track_card.dart +++ b/lib/track_card.dart @@ -29,7 +29,7 @@ class TrackCard extends StatelessWidget { border: Border.all(color: Colors.black.withValues(alpha: 0.12)), ), child: Column( - crossAxisAlignment: CrossAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Text( label, @@ -47,10 +47,10 @@ class TrackCard extends StatelessWidget { context, ).textTheme.titleMedium?.copyWith(fontWeight: FontWeight.w700), ), - const SizedBox(height: 3), + const SizedBox(height: 6), Text( subtitle.isEmpty ? 'No metadata provided' : subtitle, - maxLines: 2, + maxLines: 6, overflow: TextOverflow.ellipsis, style: Theme.of(context).textTheme.bodySmall, ), diff --git a/pubspec.yaml b/pubspec.yaml index 685e0db..0caba3d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -39,6 +39,7 @@ dependencies: audio_session: ^0.2.2 webview_flutter: ^4.13.0 http: ^1.5.0 + intl: ^0.20.2 dev_dependencies: flutter_name_manager: ^1.0.0