I have code in the initState that goes something like this (video_player package):
@override void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
final navBar = Provider.of<NavBar>(context, listen: false);
navBar.urls.forEach((element) {
navBar.videoControllers.add(
VideoPlayerController.network(
navBar.urls[videoCount],
videoPlayerOptions: VideoPlayerOptions(
allowBackgroundPlayback: false,
),
)..initialize().then((value) => navBar.initialized = true)
);
}
navBar.notify(); // This is a method that calls notifyListeners() within the NavBar class (with ChangeNotifier like how a Provider class does).
navBar.videoControllers[0].play();
navBar.notify();
}
}
The behaviour of this code is such that the video starts playing, I can hear the audio as well, but the page has not been loaded as I see no UI elements but a white screen.
Once I just do a hot reload, all the UI elements are there and I can see the video playing as well.
Where am I going wrong here?