Issue
I have a code like this :
import 'package:custom_timer/custom_timer.dart';
import 'package:fitness/core/service/date_service.dart';
import 'package:flutter/material.dart';
class StartWorkoutTimer extends StatefulWidget {
final int time;
final bool isPaused;
StartWorkoutTimer({
required this.time,
required this.isPaused,
});
@override
_StartWorkoutTimerState createState() => _StartWorkoutTimerState();
}
class _StartWorkoutTimerState extends State<StartWorkoutTimer> {
@override
Widget build(BuildContext context) {
return widget.isPaused ? _createPauseText() : _createCountdownTimer();
}
Widget _createCountdownTimer() {
return CustomTimer(
from: Duration(seconds: widget.time),
to: Duration(seconds: 0),
onBuildAction: CustomTimerAction.auto_start,
builder: (CustomTimerRemainingTime remaining) {
return Text(
"${remaining.minutes}:${remaining.seconds}",
style: TextStyle(fontSize: 17, fontWeight: FontWeight.w600),
);
},
);
}
Widget _createPauseText() {
final minutesSeconds = DateService.convertIntoSeconds(widget.time);
return Text(
"${minutesSeconds.minutes.toString().padLeft(2, '0')}:${minutesSeconds.seconds.toString().padLeft(2, '0')}",
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.w600,
),
);
}
}
But it's showing an error like this : error
Then it says that: Undefined name 'CustomTimerAction'. and : The named parameter 'onBuildAction' isn't defined.
Can please someone help with this ?
Solution
The CustomTimer doesn't have the property from but begin. Like the error said, it is required. So for your case, you have to change from to begin. Also the property onBuildAction doesn't exist.
Widget _createCountdownTimer() {
return CustomTimer(
begin: Duration(seconds: widget.time),
end: Duration(seconds: 0),
builder: (CustomTimerRemainingTime remaining) {
return Text(
"${remaining.minutes}:${remaining.seconds}",
style: TextStyle(fontSize: 17, fontWeight: FontWeight.w600),
);
},
);
}
Answered By - quoci
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.