I want to load other screen properly on my flutter app I want to load other screen properly on my flutter app dart dart

I want to load other screen properly on my flutter app


It happens because you have not passed the arguments to the constructor of Read_Pdf()

Read_Pdf(this.context, this.pdfPath);

It needs context and the pdfPath, you can do it like this

onPressed: (){         Navigator.push(        context,         MaterialPageRoute(builder: (context) => Read_Pdf(context, pdfPath)),      );    }

That it'll do it.

But in your implementation:

I can see you have a demo pdf in Read_Pdf

Change your constructor to

Read_Pdf({this.context, this.pdfPath = _documentPath});

What this.pdfPath = _documentPath does is it assigns _documentPath to pdfPath if it's not provided when Read_Pdf is instantiated.

So now the onPressed function will change to

onPressed: (){         Navigator.push(        context,         MaterialPageRoute(builder: (context) => Read_Pdf(context: context)),      );    }


If you don't need this variable to forward to class Read_pdf from other class, you must remove constructor:Read_Pdf(this.context, this.pdfPath);If you remove this one line, error disappears.

If You need this variables, you must run class with arguments:

MaterialPageRoute(builder: (context) => Read_Pdf(context: context, pdfPath: pdfPath)),


it needs context and pdf path()try the following code :

onpressesd(){Navigator.push(context,MaterialPageRoute(builder :(context) => Read_pdf(context: context)))}