Skip to content

Commit 4f7ff28

Browse files
committed
chore: monitor time
1 parent 632b5ab commit 4f7ff28

1 file changed

Lines changed: 23 additions & 25 deletions

File tree

lib/app/map/_lib/managers/monitor.dart

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class MonitorMapLayerManager extends MapLayerManager {
4545
_setupBlinkTimer();
4646
}
4747

48-
final currentRtsTime = ValueNotifier<String?>(GlobalProviders.data.rts?.time.toString());
48+
final currentRtsTime = ValueNotifier<int?>(GlobalProviders.data.rts?.time);
4949

5050
static final kRtsCircleColor = [
5151
Expressions.interpolate,
@@ -424,7 +424,7 @@ class MonitorMapLayerManager extends MapLayerManager {
424424

425425
void _onDataChanged() {
426426
final newRts = GlobalProviders.data.rts;
427-
final newRtsTime = newRts?.time.toString();
427+
final newRtsTime = newRts?.time;
428428

429429
if (newRtsTime != currentRtsTime.value) {
430430
currentRtsTime.value = newRtsTime;
@@ -687,15 +687,6 @@ class _MonitorMapLayerSheetState extends State<MonitorMapLayerSheet> {
687687

688688
bool _isCollapsed = true;
689689

690-
String _formattedTime = '';
691-
692-
@override
693-
void initState() {
694-
super.initState();
695-
widget.manager.currentRtsTime.addListener(_updateFormattedTime);
696-
_updateFormattedTime();
697-
}
698-
699690
void _toggleCollapse() {
700691
setState(() => _isCollapsed = !_isCollapsed);
701692
}
@@ -707,12 +698,6 @@ class _MonitorMapLayerSheetState extends State<MonitorMapLayerSheet> {
707698
setState(() => countdown = remainingSeconds);
708699
}
709700

710-
void _updateFormattedTime() {
711-
if (GlobalProviders.data.rts != null) {
712-
setState(() => _formattedTime = DateFormat('yyyy-MM-dd HH:mm:ss').format(DateTime.fromMillisecondsSinceEpoch(GlobalProviders.data.rts!.time)));
713-
}
714-
}
715-
716701
@override
717702
Widget build(BuildContext context) {
718703
return Selector<DpipDataModel, UnmodifiableListView<Eew>>(
@@ -1041,13 +1026,27 @@ class _MonitorMapLayerSheetState extends State<MonitorMapLayerSheet> {
10411026
left: 100,
10421027
right: 100,
10431028
child: SafeArea(
1044-
child: Container(
1045-
padding: const EdgeInsets.all(8),
1046-
color: Colors.black54,
1047-
child: Text(
1048-
textAlign: TextAlign.center,
1049-
_formattedTime,
1050-
style: const TextStyle(color: Colors.white, fontSize: 16),
1029+
child: Align(
1030+
alignment: Alignment.topCenter,
1031+
child: ValueListenableBuilder<int?>(
1032+
valueListenable: widget.manager.currentRtsTime,
1033+
builder: (context, currentTimeMillis, child) {
1034+
String displayTime = 'N/A';
1035+
if (currentTimeMillis != null && currentTimeMillis > 0) {
1036+
displayTime = DateFormat('yyyy-MM-dd HH:mm:ss').format(
1037+
DateTime.fromMillisecondsSinceEpoch(currentTimeMillis),
1038+
);
1039+
}
1040+
return Container(
1041+
padding: const EdgeInsets.all(8),
1042+
color: Theme.of(context).colorScheme.surface,
1043+
child: Text(
1044+
displayTime,
1045+
textAlign: TextAlign.center,
1046+
style: TextStyle(color: Theme.of(context).colorScheme.onSurface, fontSize: 16),
1047+
),
1048+
);
1049+
},
10511050
),
10521051
),
10531052
),
@@ -1061,7 +1060,6 @@ class _MonitorMapLayerSheetState extends State<MonitorMapLayerSheet> {
10611060
@override
10621061
void dispose() {
10631062
_timer?.cancel();
1064-
widget.manager.currentRtsTime.removeListener(_updateFormattedTime);
10651063
super.dispose();
10661064
}
10671065
}

0 commit comments

Comments
 (0)