Click here to Skip to main content
15,790,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using a video player to play the videos I get from my streambuilder. I am unable to place my dispose function in such a way that I don't get this error.

Error is causing the emulator to crash after certain point.

My screen where I am getting this error:

class _PageViewBuilderState extends State<PageViewBuilder> {
  VideoPlayerController? INvideoPlayerController;
  void initState() {
    INvideoPlayerController ='')
      ..addListener(() {})
      ..initialize().then((value) => INvideoPlayerController!.play());

  void dispose() {

  int _currentPage = 0;
  Widget build(BuildContext context) {
    return Scaffold(
      body: StreamBuilder<QuerySnapshot<Map<String, dynamic>>>(
          builder: (ctx, snapshot) {
            if (snapshot.hasError) {
              const Center(
                child: Text('Unknown Error'),

            return !snapshot.hasData
                ? const Center(
                    child: CircularProgressIndicator(),
                : PageView.builder(
                    scrollDirection: Axis.vertical,
                    onPageChanged: (int page) {
                      setState(() {
                        _currentPage = page;
                    itemBuilder: (BuildContext context, int index) {
                      INvideoPlayerController =
                            .then((value) => INvideoPlayerController!.play());
                      return Stack(alignment:, children: [
                          aspectRatio: MediaQuery.of(context).size.width /
                          //  INvideoPlayerController!.value.aspectRatio,
                          child: VideoPlayer(INvideoPlayerController!),

What I have tried:

I placed the dispose after the initialising the video player but has not worked because I am initialising the video player again.
I tried putting in build function of stream builder too but it does not work
[no name] 12-May-22 5:45am    
On what device you running? Do you have a CPU or a GPU encoding. And how you much have a RAM+ROM memory?
Kavya Bhargava 13-May-22 18:38pm    
So I am getting this device on all the android devices I ran it on

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900