var defaultmonth = int.parse(DateFormat('yyyyMM').format(DateTime.now()));
@override
void minus() {
setState(() {
if (defaultmonth != DateTime.now().year - 1) {
defaultmonth--;
}
});
}
@override
void add() {
setState(() {
if (defaultmonth != DateTime.now().year + 1) {
defaultmonth++;
}
});
}
I want to change the moon using this method. But if I run ‘mius’ on 202301, I want it to be 202212 instead of 202300. Is there anyone who can help me?
2
Answers
I guess you made your code complicated:
Generally the month calculations are different from normal integer calculations so Instead of making calculations from integers you do the calculations on DateTime objects.
Example: