在Riverpod上通过this tutorial并使用此代码会出现错误Unexpected text 'late'
class Clock extends StateNotifier<DateTime> {
Clock() : super(DateTime.now()) {
_timer = Timer.periodic(Duration(seconds: 1), (_) {
state = DateTime.now();
});
}
late final Timer _timer;
@override
void dispose() {
_timer.cancel();
super.dispose();
}
}
我的代码与链接网站上的代码完全相同.这个错误看起来很奇怪,因为我在谷歌或stackoverflow上没有发现类似的错误.