0

I want to go to another page when I click on the image in Flutter and pass the selected image to another page.

I am a beginner in Flutter, and I try to go to another page when I click on the image and scroll the selected image to another page to allow the user to choose the type of user. I try to use the on-Tap method so that when I click on the image, I go to the home page and the user picture goes to the profile page Thank you.

  • Ig. you can follow [How can I navigate between 2 classes, one of them requires passing data? in flutter](https://stackoverflow.com/a/68605773/10157127) – Md. Yeasin Sheikh May 25 '23 at 23:40

1 Answers1

2

In the onTap callback, use the Navigator

GestureDetector(
  onTap: () {
    Navigator.push(
      context,
      MaterialPageRoute(
        builder: (context) => ProfilePage(image: 'path/to/image.png'),
      ),
    );
  },
  child: Image.asset('path/to/image.png'),
),

receives the selected image as a parameter

class ProfilePage extends StatelessWidget {
  final String image;

  const ProfilePage({required this.image});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Profile Page'),
      ),
      body: Center(
        child: Image.asset(image),
      ),
    );
  }
}
Hari pootar
  • 147
  • 3