0

i created a listview in which i used the gero widget i have wrapped all the hero widgets and listview widgets in material but still I get this error and when i click the listtile it works properly but when I come to the second page I am not able to go back

homepage:

 body: Material(
        child: ListView(
          children: [
            Hero(
              tag: nyc_img,
              child: ListTile(
                leading: Image.network(
                  nyc_img,
                  height: 100,
                  width: 100,
                ),
                title: Text("New York City"),
                onTap: () {
                  Navigator.push(
                    context,
                    MaterialPageRoute(builder: (context) => NYCpage()),
                  );
                },
              ),
            ),
          ],
        ),

second page:

body: Center(
        child: Material(
          type: MaterialType.transparency,
          child: Hero(
            tag: nyc_img,
            child: Image.network(nyc_img),
          ),
        ),
      ),
Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56

2 Answers2

0

Wrap your ListTile with Material widget to solve this.

return Scaffold(
  body: ListView(
    children: [
      Hero(
        tag: nyc_img,
        child: Material(
          child: ListTile(
            // leading: Image.network(
            //   nyc_img,
            //   height: 100,
            //   width: 100,
            // ),
            title: Text("New York City"),
            onTap: () {
Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56
0

You need to Wrap the child of your Hero widget in a Material as the animated part is getting called outside of Scaffold widget so you need to pass Material widget separately

Scaffold(
  body: ListView(
    children: [
      Hero(
        tag: nyc_img,
        child: Material(
          type: MaterialType.transparency,
          child: ListTile(
            leading: Image.network(
              nyc_img,
              height: 100,
              width: 100,
            ),
            title: Text("New York City"),
            onTap: () {
              Navigator.push(
                context,
                MaterialPageRoute(builder: (context) => NYCpage()),
              );
            },
          ),
        ),
      ),
    ],
  ),
);

for the Second page

 Scaffold( 
  body: Center(
    child: Hero(
      tag: nyc_img,
      child: Material(
        type: MaterialType.transparency,
        child: Image.network(nyc_img),
      ),
    ),
  ),
);
Sagar
  • 402
  • 2
  • 10