Properly format this shit
This commit is contained in:
@@ -268,39 +268,31 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String _formatDuration(Duration duration) {
|
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 hours = duration.inHours;
|
||||||
final minutes = duration.inMinutes.remainder(60);
|
final minutes = duration.inMinutes.remainder(60);
|
||||||
final seconds = duration.inSeconds.remainder(60);
|
final seconds = duration.inSeconds.remainder(60);
|
||||||
final milliseconds = duration.inMilliseconds.remainder(1000);
|
final milliseconds = duration.inMilliseconds.remainder(1000);
|
||||||
|
|
||||||
// Round milliseconds to tenths of a second
|
// Use padLeft to ensure consistent width with leading zeros
|
||||||
final tenthsOfSecond = (milliseconds / 100).round();
|
final secondsStr = seconds.toString().padLeft(2, '0');
|
||||||
|
final msStr = milliseconds.toString().padLeft(3, '0');
|
||||||
|
|
||||||
// Build ISO 8601 format without unnecessary zeros
|
// Build output - only show non-zero hours and minutes
|
||||||
StringBuffer buffer = StringBuffer();
|
StringBuffer result = StringBuffer();
|
||||||
|
|
||||||
// Add hours only if non-zero
|
|
||||||
if (hours > 0) {
|
if (hours > 0) {
|
||||||
buffer.write('${hours}H');
|
result.write('${hours.toString().padLeft(2, '0')}H ');
|
||||||
}
|
}
|
||||||
|
if (hours > 0 || minutes > 0) {
|
||||||
// Add minutes only if hours exist or minutes non-zero
|
result.write('${minutes.toString().padLeft(2, '0')}M ');
|
||||||
if (minutes > 0) {
|
|
||||||
buffer.write('${minutes}M');
|
|
||||||
}
|
}
|
||||||
|
// Always show seconds and milliseconds
|
||||||
|
result.write('${secondsStr}S ${msStr}MS');
|
||||||
|
|
||||||
// Always include seconds
|
return result.toString();
|
||||||
buffer.write('${seconds}');
|
|
||||||
if (tenthsOfSecond > 0) {
|
|
||||||
buffer.write('.${tenthsOfSecond}');
|
|
||||||
}
|
|
||||||
buffer.write('S');
|
|
||||||
|
|
||||||
return buffer.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// For lap recording
|
// For lap recording - use the same format
|
||||||
String _formatDurationForLap(Duration duration) {
|
String _formatDurationForLap(Duration duration) {
|
||||||
return _formatDuration(duration);
|
return _formatDuration(duration);
|
||||||
}
|
}
|
||||||
@@ -352,13 +344,18 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
style: Theme.of(context).textTheme.headlineSmall,
|
style: Theme.of(context).textTheme.headlineSmall,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
Container(
|
// Use a fixed height container to prevent expanding and force horizontal scrolling if needed
|
||||||
width: 300, // Fixed width container to prevent "flashing"
|
SizedBox(
|
||||||
alignment: Alignment.center,
|
height: 50,
|
||||||
child: Text(
|
child: SingleChildScrollView(
|
||||||
_formatDuration(_elapsedTime),
|
scrollDirection: Axis.horizontal,
|
||||||
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
|
child: Text(
|
||||||
fontFamily: 'monospace', // Use monospaced font for fixed-width characters
|
_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
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
Reference in New Issue
Block a user