diff options
author | Lisandro Pérez Meyer <lpmeyer@ics.com> | 2023-11-20 17:47:26 -0300 |
---|---|---|
committer | Lisandro Perez Meyer <lpmeyer@ics.com> | 2023-11-21 12:16:40 +0000 |
commit | f533746fd7b07d71a1a3cbec8944056c0d329e84 (patch) | |
tree | 58044a004c0ed38d22cae9d6d2edb031a6f29389 /lib/presentation/screens/clock/clock.dart | |
parent | ae9ad191316ea506633c19975a7eb2861e8d17ec (diff) |
Date time updates
Original from Sabin Sajeevan <ssajeevan@ics.com>
Bug-AGL: SPEC-4971
Change-Id: I7a961e57715fdbf8b05f54dfcf8e56159cadd068
Signed-off-by: Lisandro Pérez Meyer <lpmeyer@ics.com>
Diffstat (limited to 'lib/presentation/screens/clock/clock.dart')
-rw-r--r-- | lib/presentation/screens/clock/clock.dart | 45 |
1 files changed, 10 insertions, 35 deletions
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<RealTimeClock> createState() => _RealTimeClockState(); + RealTimeClockState createState() => RealTimeClockState(); } -class _RealTimeClockState extends State<RealTimeClock> { +class RealTimeClockState extends ConsumerState<RealTimeClock> { 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), |