blob: 94be27717ed0039084e40f5590a338c99da28240 [file] [log] [blame]
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'package:fidl_fuchsia_ui_remotewidgets/fidl_async.dart';
import 'package:flutter/material.dart';
import 'package:internationalization/strings.dart';
import 'package:intl/intl.dart';
import 'package:quickui/quickui.dart';
// ignore_for_file: prefer_constructors_over_static_methods
/// Defines a [UiSpec] for displaying date and time.
class Datetime extends UiSpec {
// Localized strings.
static String get _title => Strings.dateTime;
// Icon for datetime title.
static IconValue get _icon =>
IconValue(codePoint: Icons.access_time.codePoint);
static const Duration refreshDuration = Duration(seconds: 1);
// Action to change timezone.
static int changeAction = QuickAction.details.$value;
late Timer _timer;
Datetime() {
_timer = Timer.periodic(refreshDuration, (_) => _onChange());
_onChange();
}
void _onChange() async {
spec = _specForDateTime();
}
@override
void update(Value value) async {}
@override
void dispose() {
_timer.cancel();
}
static Spec _specForDateTime() {
String dateTime = DateFormat.E().add_yMd().add_jm().format(DateTime.now());
return Spec(title: _title, groups: [
Group(
title: _title,
icon: _icon,
values: [Value.withText(TextValue(text: dateTime))]),
]);
}
}