diff --git a/lib/main.dart b/lib/main.dart index 0370aea..07055b6 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -268,39 +268,31 @@ class _MyHomePageState extends State { } String _formatDuration(Duration duration) { - // Format as ISO 8601 duration without unnecessary zeros + // Format with fixed width on a single line, hiding zero hours/minutes final hours = duration.inHours; final minutes = duration.inMinutes.remainder(60); final seconds = duration.inSeconds.remainder(60); final milliseconds = duration.inMilliseconds.remainder(1000); - // Round milliseconds to tenths of a second - final tenthsOfSecond = (milliseconds / 100).round(); + // Use padLeft to ensure consistent width with leading zeros + final secondsStr = seconds.toString().padLeft(2, '0'); + final msStr = milliseconds.toString().padLeft(3, '0'); - // Build ISO 8601 format without unnecessary zeros - StringBuffer buffer = StringBuffer(); - - // Add hours only if non-zero + // Build output - only show non-zero hours and minutes + StringBuffer result = StringBuffer(); if (hours > 0) { - buffer.write('${hours}H'); + result.write('${hours.toString().padLeft(2, '0')}H '); } - - // Add minutes only if hours exist or minutes non-zero - if (minutes > 0) { - buffer.write('${minutes}M'); + if (hours > 0 || minutes > 0) { + result.write('${minutes.toString().padLeft(2, '0')}M '); } + // Always show seconds and milliseconds + result.write('${secondsStr}S ${msStr}MS'); - // Always include seconds - buffer.write('${seconds}'); - if (tenthsOfSecond > 0) { - buffer.write('.${tenthsOfSecond}'); - } - buffer.write('S'); - - return buffer.toString(); + return result.toString(); } - // For lap recording + // For lap recording - use the same format String _formatDurationForLap(Duration duration) { return _formatDuration(duration); } @@ -352,13 +344,18 @@ class _MyHomePageState extends State { style: Theme.of(context).textTheme.headlineSmall, ), const SizedBox(height: 10), - Container( - width: 300, // Fixed width container to prevent "flashing" - alignment: Alignment.center, - child: Text( - _formatDuration(_elapsedTime), - style: Theme.of(context).textTheme.headlineMedium?.copyWith( - fontFamily: 'monospace', // Use monospaced font for fixed-width characters + // Use a fixed height container to prevent expanding and force horizontal scrolling if needed + SizedBox( + height: 50, + child: SingleChildScrollView( + scrollDirection: Axis.horizontal, + child: Text( + _formatDuration(_elapsedTime), + style: Theme.of(context).textTheme.headlineMedium?.copyWith( + fontFamily: 'monospace', // Use monospaced font for fixed-width characters + ), + softWrap: false, // Prevent text wrapping + overflow: TextOverflow.visible, // Allow text to extend beyond bounds ), ), ),