diff --git a/lib/screen/widget/real_date.dart b/lib/screen/widget/real_date.dart new file mode 100644 index 0000000..cf80e57 --- /dev/null +++ b/lib/screen/widget/real_date.dart @@ -0,0 +1,38 @@ + +import 'package:absensi_sas_flutter/app/constant.dart'; +import 'package:flutter/material.dart'; +import 'package:intl/intl.dart'; + +class RealTimeFormattedDate extends StatefulWidget { + @override + _RealTimeFormattedDateState createState() => _RealTimeFormattedDateState(); +} + +class _RealTimeFormattedDateState extends State { + late Stream _clockStream; + + @override + void initState() { + super.initState(); + _clockStream = Stream.periodic(Duration(seconds: 1), (i) => DateTime.now()); + } + + @override + Widget build(BuildContext context) { + return StreamBuilder( + stream: _clockStream, + builder: (context, snapshot) { + if (snapshot.hasData) { + String formattedDate = DateFormat('EEEE, d MMMM y', 'id_ID').format(snapshot.data!); + return Text( + formattedDate, + style: Constant.date_600(context: context).copyWith( + color: Constant.textBlack), + ); + } else { + return Text('Loading...'); + } + }, + ); + } +} \ No newline at end of file diff --git a/lib/screen/widget/real_time.dart b/lib/screen/widget/real_time.dart new file mode 100644 index 0000000..3f06fbe --- /dev/null +++ b/lib/screen/widget/real_time.dart @@ -0,0 +1,39 @@ + +import 'package:absensi_sas_flutter/app/constant.dart'; +import 'package:flutter/material.dart'; +import 'package:intl/intl.dart'; + +class RealTimeClock extends StatefulWidget { + @override + _RealTimeClockState createState() => _RealTimeClockState(); +} + +class _RealTimeClockState extends State { + late Stream _clockStream; + + @override + void initState() { + super.initState(); + _clockStream = Stream.periodic(Duration(seconds: 1), (i) => DateTime.now()); + } + + @override + Widget build(BuildContext context) { + return StreamBuilder( + stream: _clockStream, + builder: (context, snapshot) { + if (snapshot.hasData) { + String formattedTime = DateFormat('HH:mm:ss').format(snapshot.data!); + return Text( + formattedTime, + style: Constant.time_700(context: context).copyWith( + color: Constant.textBlack, + ), + ); + } else { + return Text('Loading...'); + } + }, + ); + } +} \ No newline at end of file