From f533746fd7b07d71a1a3cbec8944056c0d329e84 Mon Sep 17 00:00:00 2001 From: Lisandro Pérez Meyer Date: Mon, 20 Nov 2023 17:47:26 -0300 Subject: Date time updates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Original from Sabin Sajeevan Bug-AGL: SPEC-4971 Change-Id: I7a961e57715fdbf8b05f54dfcf8e56159cadd068 Signed-off-by: Lisandro Pérez Meyer --- lib/presentation/screens/clock/clock.dart | 45 +++++++------------------------ 1 file changed, 10 insertions(+), 35 deletions(-) (limited to 'lib/presentation/screens/clock/clock.dart') diff --git a/lib/presentation/screens/clock/clock.dart b/lib/presentation/screens/clock/clock.dart index f0858e7..ec419d6 100644 --- a/lib/presentation/screens/clock/clock.dart +++ b/lib/presentation/screens/clock/clock.dart @@ -1,6 +1,5 @@ -import 'dart:async'; - import 'package:flutter_ics_homescreen/export.dart'; +import 'package:intl/intl.dart'; class ClockPage extends ConsumerWidget { const ClockPage({super.key}); @@ -10,6 +9,7 @@ class ClockPage extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { double clockSize = MediaQuery.sizeOf(context).width * 0.51; + final currentTime = ref.watch(currentTimeProvider); return Column( crossAxisAlignment: CrossAxisAlignment.stretch, @@ -66,8 +66,9 @@ class ClockPage extends ConsumerWidget { ), ), ), - child: const AnalogClock( + child: AnalogClock( dialColor: null, + dateTime: currentTime, markingColor: null, hourNumberColor: null, secondHandColor: AGLDemoColors.jordyBlueColor, @@ -96,47 +97,21 @@ class ClockPage extends ConsumerWidget { } } -class RealTimeClock extends StatefulWidget { +class RealTimeClock extends ConsumerStatefulWidget { const RealTimeClock({super.key}); @override - State createState() => _RealTimeClockState(); + RealTimeClockState createState() => RealTimeClockState(); } -class _RealTimeClockState extends State { +class RealTimeClockState extends ConsumerState { late String _timeString; - late Timer _timer; - - @override - void initState() { - _timeString = _formatDateTime(DateTime.now()); - _timer = - Timer.periodic(const Duration(seconds: 1), (Timer t) => _getTime()); - super.initState(); - } - - @override - void dispose() { - _timer.cancel(); - super.dispose(); - } - - void _getTime() { - final DateTime now = DateTime.now(); - final String formattedDateTime = _formatDateTime(now); - if (mounted) { - setState(() { - _timeString = formattedDateTime; - }); - } - } - - String _formatDateTime(DateTime dateTime) { - return "${dateTime.hour}:${dateTime.minute.toString().padLeft(2, '0')}"; - } + DateFormat dateFormat = DateFormat('hh:mm a'); @override Widget build(BuildContext context) { + final currentTime = ref.watch(currentTimeProvider); + _timeString = dateFormat.format(currentTime); return Text( _timeString, style: GoogleFonts.brunoAce(color: Colors.white, fontSize: 128), -- cgit 1.2.3-korg