У меня есть будущий строительный блок, который запускается, и мне нужно, чтобы он загружал видео, прежде чем он снова будет вызывать саму функцию.
Вы не можете видеть следующие отпечатки: currentMainImage: x showImage () Waiting waitTimeSNAPSHOT ... SNAPSHOT ...
Future<void> showImage() async {
int waitTime;
String type;
(currentImage == playList.length) ? currentImage = 0 : currentImage =
currentImage;
waitTime = int.parse(playList[currentImage]["transTime"]);
print("showImage() - Waiting $waitTime s.");
Future.delayed(Duration(seconds: waitTime), () {
print("IM INSIDE FUTURE DELAYED");
setState(() {
print("SETTING STATE");
if(playerController.value.isPlaying) {
playerController.setVolume(0.0);
playerController.removeListener(listener);
print("PLAYER IS PLAYING _ DISABLE");
}
currentImage++;
(currentImage == playList.length) ? currentImage = 0 : currentImage = currentImage;
type = playList[currentImage]["type"];
print("TYPE: $type");
if(type == "image") {
print("SETTING IMAGE:");
currentMainImage = getRealFilename(playList[currentImage]["file"]);
print("CurrentMainImage: $currentMainImage");
playlistWidget = new FutureBuilder(
future: _getLocalFile(currentMainImage),
builder: (BuildContext context, AsyncSnapshot<File> snapshot) {
print("SNAPSHOT : ${snapshot.data}");
if(snapshot.data != null) {
return Padding(
padding: EdgeInsets.only(bottom: 22.0, left: 7.0),
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.fill,
image: FileImage(snapshot.data),
),
),
height: 326.0,
width: 590.0,
alignment: Alignment.center,
)
);
} else {
return CircularProgressIndicator();
}
}
);
} else if(type == "mp4") {
print("SETTING VIDEO:");
currentMainVideo = getRealFilename(playList[currentImage]["file"]);
playlistWidget = new FutureBuilder(
future: _getLocalFile(currentMainVideo),
builder: (BuildContext context, AsyncSnapshot<File> snapshot) {
print("SNAPSHOT : ${snapshot.data}");
if (snapshot.data != null) {
playerController = VideoPlayerController.file(snapshot.data)
..setVolume(0.0)
..initialize()
..play();
playerController.addListener(listener);
return Padding(
padding: EdgeInsets.only(bottom: 22.0,left: 7.0),
child: Container(
height: 326.0,
width: 590.0,
alignment: Alignment.center,
child: VideoPlayer(
playerController
),
),
);
} else {
return CircularProgressIndicator();
}
}
);
} else {
print("BIG ERROR");
}
print("CALLING SHOWIMAGE()");
showImage();
});
});
}
Фактические результаты состоят в том, что когда я вхожу в setState и набираю «video», он снова вызывает showImage (), прежде чем даже показывать видео.это вызывает два вызова функции и застревает приложение.