Closed tneotia closed 4 years ago
Hi, please add a minimal reproduce code.
@ghprod
Didn't get a chance to test but this should hopefully work. Basically press 'next route' on home screen, this will take you to named route with no params. Then tap back page and remove route, observe that in logs of [Getx] the route is removed and the controller is deleted.
Then go to next route and then click go to last page, and finally press the floating action button which will take you back to main screen. Again observe the logs and in this case it will remove a 'null' route and not delete the controller.
Hi,
Next time please add minimal reproduce code that we can run on our local by just copy-pasting the code.
Regarding your issue, it's work fine with GetX 3.11.1
import 'package:flutter/material.dart';
import 'package:get/get.dart';
main() => runApp(App());
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GetMaterialApp(
initialRoute: '/first',
getPages: [
GetPage(
name: '/first',
page: () => FirstScreen(),
binding: BindingsBuilder(() {
Get.lazyPut<FirstController>(() => FirstController());
}),
),
GetPage(
name: '/second',
page: () => SecondScreen(),
binding: BindingsBuilder(() {
Get.lazyPut<SecondController>(() => SecondController());
}),
),
GetPage(
name: '/third',
page: () => ThirdScreen(),
binding: BindingsBuilder(() {
Get.lazyPut<ThirdController>(() => ThirdController());
}),
),
],
);
}
}
class FirstController extends GetxController {}
class SecondController extends GetxController {
final title = 'Second'.obs;
}
class ThirdController extends GetxController {
final title = 'Third'.obs;
}
class FirstScreen extends GetView<FirstController> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
RaisedButton(
onPressed: () {
Get.toNamed('/second?id=x');
},
child: Text('Go to Second'),
),
RaisedButton(
onPressed: () {
Get.toNamed('/third?id=x');
},
child: Text('Go to Third'),
),
],
),
),
);
}
}
class SecondScreen extends GetView<SecondController> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: RaisedButton(
onPressed: () {
Get.back();
},
child: Text('Back to First from ${controller.title.value}'),
),
),
);
}
}
class ThirdScreen extends GetView<ThirdController> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: RaisedButton(
onPressed: () {
Get.offNamed('/first');
},
child: Text('Off to First ${controller.title.value}'),
),
),
);
}
}
Okay, sorry about that - thought the code would work. Thanks for confirming!
If it's working, i will close this issue.
Describe the bug I am using parameters in my route names to pass data between screens. Whenever I want to delete this screen from the tree, I would do Get.offNamed, but it doesn't delete the route and its controller. I get this in the logs:
whereas with Get.back (which works properly), I get this:
To Reproduce Steps to reproduce the behavior:
Get.toNamed("/screenB?id=test")
)Expected behavior Screen C's controller should be deleted as well with Get.offNamed() and parameters.
Flutter Version: v1.21.0-pre
Getx Version: v3.10.2
Describe on which device you found the bug: ex: Galaxy S8 (Android 9)