Hi can anyone please tell me what is wrong with this code. I'm trying to create a countdown timer in my widget,
class _SaleSuccessDialogState extends State<SaleSuccessDialog> {
final ValueNotifier<int> counter = ValueNotifier(10);
Timer? countDownTimer;
@override
void initState() {
super.initState();
if (App.preferences.kTillLockAfterSale) {
Timer.periodic(const Duration(seconds: 1), (timer) {
countDownTimer ??= timer;
setState(() => counter.value--);
if (counter.value == 0) {
timer.cancel();
}
});
}
}
ValueListenableBuilder(
valueListenable: counter,
builder: (context, counterValue, child) {
return Text("Counter:$counterValue");
},
),
This is the error that I'm getting:
Dart Unhandled Exception: type 'int' is not a subtype of type 'ValueNotifier' of 'function result'