-
Notifications
You must be signed in to change notification settings - Fork 27.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Navigator pop parameter can not be String #87262
Comments
Hi @hongwei78, code sample
if you are still facing the issue, then please provide the output of Thank you. |
|
Hi @maheshmnj code sampleimport 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'dart:async';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
onGenerateRoute: Router.generateRoute,
initialRoute: RouteName.first,
theme: ThemeData(primarySwatch: Colors.blue),
home: Popview(title: 'title'));
// MyHomePage(title: 'App title'));
}
}
class Popview extends StatefulWidget {
const Popview({Key? key, required this.title}) : super(key: key);
final String title;
@override
_PopviewState createState() => _PopviewState();
}
class _PopviewState extends State<Popview> {
String stringFromActivity = 'Send Data on Pop';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
stringFromActivity,
style: const TextStyle(fontSize: 20.0),
textAlign: TextAlign.center,
),
Container(
height: 20.0,
),
ElevatedButton(
child: const Text('tap me'),
onPressed: () => _push(),
)
],
),
),
);
}
Future _push() async {
Object? results = await Navigator.of(context).pushNamed(RouteName.second);
if (results != null) {
setState(() {
print('Data received on pop $results');
});
}
}
}
class SecondScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Selecte Smily'),
),
body: ListView.builder(
itemBuilder: (context, i) {
return ListTile(
title: Text('item $i'),
onTap: () {
Navigator.of(context).pop('SEND THIS');
},
);
},
itemCount: 20,
),
);
}
}
class RouteName {
static const String first = 'first';
static const String second = 'second';
}
class Router {
static Route<dynamic> generateRoute(RouteSettings settings) {
switch (settings.name) {
case RouteName.first:
return CupertinoPageRoute<bool>(
settings: RouteSettings(name: 'first'),
builder: (_) => Popview(
title: 'first',
));
case RouteName.second:
return CupertinoPageRoute<bool>(
settings: RouteSettings(name: settings.name),
builder: (_) => SecondScreen());
default:
return CupertinoPageRoute<bool>(
settings: RouteSettings(name: settings.name),
builder: (_) => Scaffold(
body: Center(
child: Text('No route defined for ${settings.name}'),
),
));
}
}
}
/// Pop路由
class PopRoute extends PopupRoute {
PopRoute({required this.child});
Widget child;
final Duration _duration = Duration(milliseconds: 300);
@override
Color? get barrierColor => null;
@override
bool get barrierDismissible => true;
@override
String? get barrierLabel => null;
@override
Duration get transitionDuration => _duration;
@override
Widget buildPage(BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation) {
return child;
}
} |
@hongwei78 thanks for the complete reproducible code I checked your code the issue is that the type is mismatched You are expecting the CupertinoPageRoute to take bool here
And while popping the widget you are passing a String
You have to make sure both types are the same. Feel free to comment if you need any further clarification, Closing this issue as invalid if you disagree please comment with your reasoning and I will reopen it. |
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 |
Navigator.of(context).pop('cart');
It's not worked.
Expected results:
page closed
Actual results:
Unhandled Exception: type 'String' is not a subtype of type 'bool?' of 'result'
Navigator pop not work
[VERBOSE-2:ui_dart_state.cc(199)] Unhandled Exception: type 'String' is not a subtype of type 'bool?' of 'result'
#0 LocalHistoryRoute.didPop (package:flutter/src/widgets/routes.dart)
#1 _RouteEntry.pop
package:flutter/…/widgets/navigator.dart:3085
#2 NavigatorState.pop
package:flutter/…/widgets/navigator.dart:5077
#3 GoodsDetailPage.detailBottom..
package:igocctv/…/goods/goodsdetail_page.dart:391
#4 GoodsDetailPage.detailBottom..
package:igocctv/…/goods/goodsdetail_page.dart:388
#5 _InkResponseState._handleTap
package:flutter/…/material/ink_well.dart:989
#6 GestureRecognizer.invokeCallback
package:flutter/…/gestures/recognizer.dart:182
#7 TapGestureRecognizer.handleTapUp
package:flutter/…/gestures/tap.dart:607
#8 BaseTapGestureRecognizer._checkUp
package:flutter/…/gestures/tap.dart:296
#9 BaseTapGestureRecognizer.<…>
Flutter 2.2.3
flutter/packages/flutter/lib/src/widgets/routes.dart
line 636: bool didPop(T? result) {
T's type is bool,is not String
The text was updated successfully, but these errors were encountered: