Repository navigation
Closed
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listf: routesNavigator, Router, and related APIs.Navigator, Router, and related APIs.found in release: 3.3Found to occur in 3.3Found to occur in 3.3found in release: 3.7Found to occur in 3.7Found to occur in 3.7has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagespackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-designOwned by Design Languages teamOwned by Design Languages teamtriaged-designTriaged by Design Languages teamTriaged by Design Languages teamworkaround availableThere is a workaround available to overcome the issueThere is a workaround available to overcome the issue
Description
Hi, I found an uncertain problem!
Problem description:
I expect to use
Navigator.of(context).pop<String>to return a value of a certain type, but the result is always a value of dynamic type.
Code:
// First screen
Navigator.of(context).pushNamed<String>('login').then((String result){
print('login.result runtimeType: ${result.runtimeType}');
});
// Second screen
Navigator.of(context).pop<String>('success');A type error will occur in the above code:
E/flutter (16614): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: type 'MaterialPageRoute<dynamic>' is not a subtype of type 'Route<String>' in type cast
E/flutter (16614): #0 NavigatorState._routeNamed (package:flutter/src/widgets/navigator.dart:3138:55)
E/flutter (16614): #1 NavigatorState.pushNamed (package:flutter/src/widgets/navigator.dart:3190:20)
E/flutter (16614): #2 _Transfer.build.<anonymous closure> (package:example/views/FirstScreen.dart:157:55)
E/flutter (16614): #3 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter (16614): #4 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:504:11)
E/flutter (16614): #5 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:282:5)
E/flutter (16614): #6 BaseTapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:254:7)
E/flutter (16614): #7 GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27)
E/flutter (16614): #8 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:222:20)
E/flutter (16614): #9 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
E/flutter (16614): #10 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
E/flutter (16614): #11 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
E/flutter (16614): #12 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
E/flutter (16614): #13 _rootRunUnary (dart:async/zone.dart:1196:13)
E/flutter (16614): #14 _CustomZone.runUnary (dart:async/zone.dart:1085:19)
E/flutter (16614): #15 _CustomZone.runUnaryGuarded (dart:async/zone.dart:987:7)
E/flutter (16614): #16 _invoke1 (dart:ui/hooks.dart:275:10)
E/flutter (16614): #17 _dispatchPointerDataPacket (dart:ui/hooks.dart:184:5)
E/flutter (16614): Reacted by rostyslavroshak, Stéphane Roche, januwA, Amir Muhammad Hakim, Katarina Sheremet, Dmitry Boltachev, José Luis, Mateus Felipe C. C. Pinto, Benjamin Bisinger, Andres M. Cubas and 2 more
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listf: routesNavigator, Router, and related APIs.Navigator, Router, and related APIs.found in release: 3.3Found to occur in 3.3Found to occur in 3.3found in release: 3.7Found to occur in 3.7Found to occur in 3.7has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagespackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-designOwned by Design Languages teamOwned by Design Languages teamtriaged-designTriaged by Design Languages teamTriaged by Design Languages teamworkaround availableThere is a workaround available to overcome the issueThere is a workaround available to overcome the issue
Activity
liodali commentedon May 14, 2020
you don't need to make pushNamed() or pop()
just pushNamed("routeName") and pop(value)
you will get right type
VladyslavBondarenko commentedon May 14, 2020
Thanks @liodali ,
It should be solved by this, closing.
@notescript If you disagree please write in the comments and I will reopen it
https://flutter.dev/docs/cookbook/navigation/returning-data#interactive-example
HannibalKcc commentedon Jun 15, 2020
Hi @VladyslavBondarenko ,
your example used
Navigator.push(), return data's type work well.But, i find if i use
Navigator.pushNamed()replaceNavigator.push()it throw A type error will occur as same as @notescript showed.you can check code
here
liodali commentedon Jun 15, 2020
replace String result by var result,should work for you
HannibalKcc commentedon Jun 16, 2020
@liodali use
varwork for me.But i think API
Navigator.pushNamed()andNavigator.push()should have the same result,even certain a type.[-]Navigator.of(context).pushNamed<T> cannot determine the type of T[/-][+]Unhandled Exception: type 'MaterialPageRoute<dynamic>' is not a subtype of type 'Route<String>' in type cast[/+]celesteking commentedon Nov 17, 2020
This is a deficiency on flutter's Navigator1/MaterialApp side when
routestable is being used. This isn't documented anywhere, but it should've been. The workaround is to stop providingpushNamedany type, but instead typecast to it later:This needs fixing, either on doc or code 's side.
chunhtai commentedon Oct 10, 2022
This is also blocking internal migration
6 remaining items
flutter-triage-bot commentedon Jan 12, 2024
This issue is missing a priority label. Please set a priority label when adding the
triaged-designlabel.equescodebelike commentedon Aug 14, 2025
I had similar problem, but with auto_route navigation, so I fixed cast issue by adding
<type>to CustomRoute declaration:Fix `Navigator.pushNamed<T>()` type checking (flutter#188148)
github-actions commentedon Sep 10, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.