0

I got the problem when I try to navigation page. I want to user Navigation from cart page to home page and cannot back to cart page. But I got the error like this:

type 'String' is not a subtype of type 'Route<Object?>' in type cast

I have try a lot to fix the code, but it didn't work.

The code:

TextButton(
    onPressed: () {
        Navigator.pushNamedAndRemoveUntil(context, '/home', (route) => false);
    },)

How to fix it?

user16217248
  • 3,119
  • 19
  • 19
  • 37
leo
  • 139
  • 9
  • Could you show your **RouteFactory = Route? Function( RouteSettings settings )** function code? – Hoa Le Mar 31 '23 at 04:11

1 Answers1

0

The defination of pushAndRemoveUntil is:

Future<T?> pushAndRemoveUntil<T extends Object?>(
   BuildContext context,
   Route<T> newRoute,
   RoutePredicate predicate
)

Use the following updated code:

Navigator.pushAndRemoveUntil(
  context,
  MaterialPageRoute(builder: (context) => HomePage()),
  (route) => false,
);
krishnaacharyaa
  • 14,953
  • 4
  • 49
  • 88
  • Hi @leo, I am glad it worked, please consider upvoting the post aswell if it solved your problem, It helps further for the people having same issue. Thank you – krishnaacharyaa Mar 31 '23 at 07:03