I want to be able to display the current calendar week, but as far as I have seen that isn't possible with DateTime.
Currently I have to get the current day number, divide it by 7 and round up that number. The last part is where I'm stuck at. Is there a way to round up integers in Flutter?
Here is the code I use:
class CurrentWeek extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return new CurrentWeekState();
}
}
class CurrentWeekState extends State<CurrentWeek> {
DateTime currentTime;
String currentDayCount;
@override
void initState() {
super.initState();
currentTime = DateTime.now();
}
@override
Widget build(BuildContext context) {
currentDayCount = DateFormat("D").format(currentTime);
return Text(currentDayCount);
}
}
The package: https://pub.dev/packages/week_of_year does exactly this by just calling this on a DateTime Object:
As stated in the documentation:
import 'package:week_of_year/week_of_year.dart';
void main() {
final date = DateTime.now();
print(date.weekOfYear); // Get the iso week of year
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With