Dart Flutter - 命名参数“begin”是必需的,但没有相应的参数
我有这样的代码:
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,
),
);
}
}
但它显示了这样的错误: 错误
然后它说:未定义名称“CustomTimerAction”。 并且:未定义命名参数“onBuildAction”。
有人可以帮忙吗?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
CustomTimer 没有属性
from
但 开始。正如错误所说,这是必需的。因此,对于您的情况,您必须将from
更改为begin
。此外,属性onBuildAction
也不存在。The CustomTimer doesn't have the property
from
but begin. Like the error said, it is required. So for your case, you have to changefrom
tobegin
. Also the propertyonBuildAction
doesn't exist.