[Homepage] 3. add date & time widget
This commit is contained in:
38
lib/screen/widget/real_date.dart
Normal file
38
lib/screen/widget/real_date.dart
Normal file
@@ -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<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...');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
39
lib/screen/widget/real_time.dart
Normal file
39
lib/screen/widget/real_time.dart
Normal file
@@ -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<RealTimeClock> {
|
||||||
|
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 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...');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user