Reputation: 43
I have navigate from Dashboard to Some Screen called 'A'. In that screen, I have shown a listing using ListView Builder. In that, clicking on item in ListView navigate to another Screen called "B". When I press back button in that Screen "B" its navigate to Dashboard. But it has to navigate to Screen "A". Please help me to resolve this issue.
In Dashboard, I have use below code to Navigate to Screen "A",
_showSnackBar(BuildContext context, Item item) {
switch(item.name)
{
case "Disputes":
Navigator.push(context, MaterialPageRoute(builder: (context)=> Disputes()));
break;
}
}
}
In Screen "A", I have use below code to Navigate to Screen "B",
Card(
child: ListTile(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
SubmitDisputes(disputesId: disputeResList[index].id.toString())));
},
trailing: Icon(
Icons.remove_red_eye),
));
}),
),
),
When I press back button in Screen "B", its navigate to Dashboard. But I need to navigate to "A" as per the backstacks.
Please help me!
Upvotes: 4
Views: 1466
Reputation: 2862
So as discussed in the comments. using Navigator.of(context,rootNavigator: true).push(...)
fixed the issue.
But why did you faced this issue at first ? because you have multiple MaterialApp
in your app. you have to keep only the one in main.dart
as root widget. so you have two options:
MaterialApp
as root widget and call Navigator.of(context).push(...)
MaterialApp
and use Navigator.of(context,rootNavigator: true).push(...)
If you need my advice, use 1.
Upvotes: 6