Properly format this shit
This commit is contained in:
@@ -268,39 +268,31 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
}
|
||||
|
||||
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 ');
|
||||
}
|
||||
if (hours > 0 || minutes > 0) {
|
||||
result.write('${minutes.toString().padLeft(2, '0')}M ');
|
||||
}
|
||||
// Always show seconds and milliseconds
|
||||
result.write('${secondsStr}S ${msStr}MS');
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
// Add minutes only if hours exist or minutes non-zero
|
||||
if (minutes > 0) {
|
||||
buffer.write('${minutes}M');
|
||||
}
|
||||
|
||||
// Always include seconds
|
||||
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) {
|
||||
return _formatDuration(duration);
|
||||
}
|
||||
@@ -352,14 +344,19 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
style: Theme.of(context).textTheme.headlineSmall,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Container(
|
||||
width: 300, // Fixed width container to prevent "flashing"
|
||||
alignment: Alignment.center,
|
||||
// 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
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 30),
|
||||
|
Reference in New Issue
Block a user