Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
When I try to pass an image from one screen to another I get an error.

Here the error:
Prefer typing uninitialized variables and fields.
Use generic function type syntax for parameters.
The prefix 'image1' can't be used here because it's shadowed by a local declaration.
Try renaming either the prefix or the local declaration.


What I have tried:

First screen :
class FirstPage extends StatefulWidget {
FirstPage({
Key? key, required this.image1}) : super(key: key);
final XFile image1;
child: Image1.file(File(image1.path)),
Second Screen:
Future<void> _openImagePicker() async {
final XFile? pickedImage =
await _picker.pickImage(source: ImageSource.gallery);
if (pickedImage == null) return;
Navigator.of(context)
.push(MaterialPageRoute(builder: (_) => FirstPage(image1: pickedImage)));
Posted
Updated 10-Aug-22 6:48am
v3
Comments
Richard MacCutchan 10-Aug-22 7:08am    
"I get an error."
Unfortunately my crystal ball has clouded over so I cannot see your screen. Maybe you could actually tell us what error and where it occurs.
Priya Smarteer 10-Aug-22 9:13am    
Thanks for your response! When I try to send an image from one screen to another I get the below errors.

Prefer typing uninitialized variables and fields.
Use generic function type syntax for parameters.
The prefix 'image1' can't be used here because it's shadowed by a local declaration.
Try renaming either the prefix or the local declaration.

First screen :

class FirstPage extends StatefulWidget {


FirstPage({
Key? key, required this.image1}) : super(key: key);
final XFile image1;

child: Image1.file(File(image1.path)),

Second screen:

Future<void> _openImagePicker() async {
final XFile? pickedImage =
await _picker.pickImage(source: ImageSource.gallery);
if (pickedImage == null) return;
Navigator.of(context)
.push(MaterialPageRoute(builder: (_) => FirstPage(image1: pickedImage)));
Priya Smarteer 10-Aug-22 9:13am    
Thanks for your response! When I try to send an image from one screen to another I get the below errors.

Prefer typing uninitialized variables and fields.
Use generic function type syntax for parameters.
The prefix 'image1' can't be used here because it's shadowed by a local declaration.
Try renaming either the prefix or the local declaration.

First screen :

class FirstPage extends StatefulWidget {


FirstPage({
Key? key, required this.image1}) : super(key: key);
final XFile image1;

child: Image1.file(File(image1.path)),

Second screen:

Future<void> _openImagePicker() async {
final XFile? pickedImage =
await _picker.pickImage(source: ImageSource.gallery);
if (pickedImage == null) return;
Navigator.of(context)
.push(MaterialPageRoute(builder: (_) => FirstPage(image1: pickedImage)));

1 solution

Something wrong on this line.
child: Image1.file(File(image1.path)),
child suppose return Widget, not Image1.file

What is Image1 exactly? Is it the class created by you or it's an library?
 
Share this answer
 
v2

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