38 lines
1.1 KiB
Dart
38 lines
1.1 KiB
Dart
|
|
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<RealTimeFormattedDate> {
|
|
late Stream<DateTime> _clockStream;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_clockStream = Stream<DateTime>.periodic(Duration(seconds: 1), (i) => DateTime.now());
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return StreamBuilder<DateTime>(
|
|
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...');
|
|
}
|
|
},
|
|
);
|
|
}
|
|
} |