tylkonachwile
tylkonachwile

Reputation: 2277

Navigate to other page

I use a Datepicker Cupertiono in my Flutter application:

https://github.com/wuzhendev/flutter-cupertino-date-picker

There is a method named "onConfirm()" where I'm trying to redirect user to other page, but with no luck. I tried

return        Navigator.pushReplacementNamed(ctx, '/otherPage');

but what actually happens when this return statment is hit, is cupertino widget closes and nothing happen. There is no error

When I try to use :

return Navigator.pushNamed<bool>(
                          ctx,
                          '/route/' + object.id.toString());

Some errors apear:

Performing hot restart...
Restarted application in 1 685ms.
I/flutter (20542): 112
E/flutter (20542): [ERROR:flutter/shell/common/shell.cc(188)] Dart Error: Unhandled exception:
E/flutter (20542): Looking up a deactivated widget's ancestor is unsafe.
E/flutter (20542): At this point the state of the widget's element tree is no longer stable. To safely refer to a widget's ancestor in its dispose() method, save a reference to the ancestor by calling
inheritFromWidgetOfExactType() in the widget's didChangeDependencies() method.
E/flutter (20542):
E/flutter (20542): #0      Element._debugCheckStateIsActiveForAncestorLookup.<anonymous closure> (package:flutter/src/widgets/framework.dart:3232:9)
E/flutter (20542): #1      Element._debugCheckStateIsActiveForAncestorLookup (package:flutter/src/widgets/framework.dart:3241:6)
E/flutter (20542): #2      Element.ancestorStateOfType (package:flutter/src/widgets/framework.dart:3289:12)
E/flutter (20542): #3      Scaffold.of (package:flutter/src/material/scaffold.dart:935:42)

Upvotes: 0

Views: 263

Answers (1)

Guy Luz
Guy Luz

Reputation: 4039

You should use Navigator.push. Import your page, example: import './otherPage.dart';

Than change your line

return Navigator.pushReplacementNamed(ctx, '/otherPage');

To

return Navigator.push(context, 'otherClassName');

Upvotes: 1

Related Questions