Android studio 颤振无法将00.00转换为秒,unseconds()方法显示错误
我正在尝试制作音频播放器,但在查找歌曲当前持续时间的滑块时遇到问题, 谢谢,Android studio 颤振无法将00.00转换为秒,unseconds()方法显示错误,android-studio,flutter,dart,Android Studio,Flutter,Dart,我正在尝试制作音频播放器,但在查找歌曲当前持续时间的滑块时遇到问题, 谢谢, @override void initState() { super.initState(); player.onAudioPositionChanged.listen((Duration duration) { setState(() { currenttime = duration; }); }); player.onDurationChanged.listen((Duration duration
@override
void initState() {
super.initState();
player.onAudioPositionChanged.listen((Duration duration) {
setState(() {
currenttime = duration;
});
});
player.onDurationChanged.listen((Duration duration) {
setState(() {
totaltime = duration;
});
});
}
这是捕获CURRENTTIME和TOTALTIME的滑块小部件
Slider(
value: currenttime.inSeconds.toDouble(),
max: totaltime.inSeconds.toDouble(),
min: 0.0,
activeColor: mycolor,
inactiveColor: Colors.grey,
onChanged: (double value) {
setState(() {
int second = value.toInt();
Duration seeked = Duration(seconds: second);
player.seek(seeked);
value = value;
});
}),
这就是错误所在
═╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following NoSuchMethodError was thrown building MyApp(dirty, state: _MyAppState#8e9ee):
The getter 'inSeconds' was called on null.
Receiver: null
Tried calling: inSeconds
使用三元运算符,因为
currenttime
最初似乎为空,或者调查它为何为空
Slider(
value: currenttime != null? currenttime.inSeconds.toDouble() : 0.0,
看起来它是空的尝试调试该值,您将know@OMiShah如何调试?抱歉,如果这很愚蠢的话。我的意思是,试着打印那个变量的值。最有可能的情况是,您试图在初始化一个空变量之前转换它,这会导致问题