【发布时间】:2021-08-27 12:50:18
【问题描述】:
我的应用程序的主屏幕是横向的,并且有背景音乐。所以在 initstate 中,我将屏幕实现为风景,带有音乐
void initState() {
super.initState();
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
]);
_assetsAudioPlayer = AssetsAudioPlayer();
AssetsAudioPlayer.newPlayer().open(
Audio("assets/audio/bgm.mp3"),
autoStart: true,
showNotification: true,
);
_assetsAudioPlayer!.playOrPause();
}
@override
void dispose() {
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
_assetsAudioPlayer = null;
super.dispose();
}
所有这些都应该只包含在主屏幕本身中,我不希望它传递到任何其他屏幕。但是音乐和方向被传递到下一个屏幕。我怎样才能将其仅包含在主屏幕上。?
【问题讨论】: