-
Notifications
You must be signed in to change notification settings - Fork 26.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
The argument type 'ModalRoute<Object?>?' can't be assigned to the parameter type 'PageRoute<dynamic>' #62023
Comments
Hi @Yetispapa |
@TahaTesser Sure. I updated my issue accordingly. |
Hi @Yetispapa |
@TahaTesser, Here you go:
Its right after creating a flutter app. So you can just copy and paste it in |
Code Sample
logs
flutter doctor -v
|
Hi @Yetispapa . Did you manage to fix this issue? |
Using routeObserver.subscribe(this, ModalRoute.of(context) as PageRoute); seems to work for me. It might not work if you are using that code inside a widget that is displayed by a |
I can reproduce the issue though, You will need to typecase ModalRoute to PageRoute as mentioned above. I believe this is more of a documentation issue rather than a bug. code sampleimport 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
final RouteObserver<PageRoute> routeObserver = RouteObserver<PageRoute>();
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
navigatorObservers: [routeObserver],
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
// This makes the visual density adapt to the platform that you run
// the app on. For desktop platforms, the controls will be smaller and
// closer together (more dense) than on mobile platforms.
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(),
);
}
}
class RouteAwareWidget extends StatefulWidget {
const RouteAwareWidget({super.key});
@override
State<RouteAwareWidget> createState() => RouteAwareWidgetState();
}
// Implement RouteAware in a widget's state and subscribe it to the RouteObserver.
class RouteAwareWidgetState extends State<RouteAwareWidget> with RouteAware {
@override
void didChangeDependencies() {
super.didChangeDependencies();
routeObserver.subscribe(this, ModalRoute.of(context)! as PageRoute);
}
@override
void dispose() {
routeObserver.unsubscribe(this);
super.dispose();
}
@override
void didPush() {
// Route was pushed onto navigator and is now topmost route.
}
@override
void didPopNext() {
// Covering route was popped off the navigator.
}
@override
Widget build(BuildContext context) => Container();
}
class MyHomePage extends StatelessWidget {
const MyHomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(),
floatingActionButton: FloatingActionButton(
onPressed: () {
showGeneralDialog<void>(
useRootNavigator: false,
barrierLabel: "modal",
barrierDismissible: true,
barrierColor: Colors.black.withOpacity(0.5),
transitionDuration: const Duration(milliseconds: 400),
context: context,
pageBuilder: (context, anim1, anim2) {
return RouteAwareWidget();
},
transitionBuilder: (context, anim1, anim2, child) {
return SlideTransition(
position: Tween(begin: const Offset(0, 1), end: const Offset(0, 0))
.animate(anim1),
child: child,
);
},
);
},
tooltip: 'Show Dialog',
child: const Icon(Icons.present_to_all),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
flutter doctor -v (mac)
cc: @chunhtai |
Hello, I find the RouteObserver is still wrong: @override
void didChangeDependencies() {
super.didChangeDependencies();
routeObserver.subscribe(this, ModalRoute.of(context)!);
} code above should be changed to: routeObserver.subscribe(this, ModalRoute.of(context) as PageRoute); Also, when using |
This issue is missing a priority label. Please set a priority label when adding the |
Steps to Reproduce:
1.) setup
RouteObservers
on a widget (lets call itMyWidget
) like in example: https://api.flutter.dev/flutter/widgets/RouteObserver-class.html2.) use
showGeneralDialog
to presentMyWidget
Expected results:
MyWidget
should subscribe toRouteObservers
without throwing an exceptionActual results:
exception is throwed:
type '_DialogRoute<void>' is not a subtype of type 'PageRoute<dynamic>'
Exception is throwed here:
flutter doctor -v
flutter run --verbose
logs
The text was updated successfully, but these errors were encountered: