Sana'a Al-ahdal
Sana'a Al-ahdal

Reputation: 1780

flutter Navigator.push doesn't work and show me this error NoSuchMethodError: The method 'ancestorStateOfType' was called on null

I have a list of items and i want when the user click on an item, appear another window, i write the code as shown bellow

return ListTile( leading: Container(
 padding: EdgeInsets.only(left: 8.0 , top: 8.0 ,bottom: 8.0),
 child: Column(
   children: <Widget>[
     _buildGymLocationRow(gym), // method 
      SizedBox(height: 5.0,),
     _builDescrRateRow(gym), ], ), )

,onTap: (){ Navigator.push( context, new MaterialPageRoute(builder: (context) => new gymDetails()));
},
);

but when i click on the item or ListTile, it's show me this error.. i don't know what i have to do.. please I need help

I/flutter ( 9134): Another exception was thrown: NoSuchMethodError: The method 'ancestorStateOfType' was called on null.

Upvotes: 0

Views: 1152

Answers (1)

Omatt
Omatt

Reputation: 10453

The error NoSuchMethodError: The method 'ancestorStateOfType' was called on null. thrown is most likely caused by the widget having been removed from the tree. It's possible that it doesn't have a context anymore. To solve this issue, you may want to consider keeping track of the BuildContext context that you're using by storing it as a variable or passing it as a parameter.

Upvotes: 2

Related Questions