mirror of
https://github.com/R0m1k3/xtremflow.git
synced 2026-10-12 01:36:20 +02:00
56 lines
1.1 KiB
Dart
56 lines
1.1 KiB
Dart
import 'dart:async';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:intl/intl.dart';
|
|
|
|
class ClockWidget extends StatefulWidget {
|
|
final TextStyle? style;
|
|
|
|
const ClockWidget({super.key, this.style});
|
|
|
|
@override
|
|
State<ClockWidget> createState() => _ClockWidgetState();
|
|
}
|
|
|
|
class _ClockWidgetState extends State<ClockWidget> {
|
|
late DateTime _now;
|
|
Timer? _timer;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_now = DateTime.now();
|
|
_startTimer();
|
|
}
|
|
|
|
void _startTimer() {
|
|
_timer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
|
if (mounted) {
|
|
setState(() {
|
|
_now = DateTime.now();
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_timer?.cancel();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// Format: HH:mm
|
|
final timeString = DateFormat('HH:mm').format(_now);
|
|
return Text(
|
|
timeString,
|
|
style: widget.style ?? const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.bold,
|
|
shadows: [Shadow(color: Colors.black, blurRadius: 4)],
|
|
),
|
|
);
|
|
}
|
|
}
|