Closed kiaxseventh closed 2 years ago
Hi @kiaxseventh, I am glad you liked it. Thanks. To do this, you can define a middleware like this:
import 'package:get/get.dart';
import 'package:qlevar_router/qlevar_router.dart';
class ControllerRegister<T> extends QMiddleware {
final T Function() creator;
final bool lazy;
ControllerRegister(this.creator, {this.lazy = true});
@override
Future onEnter() async {
if (!Get.isRegistered<T>()) {
if (lazy) {
Get.lazyPut(creator);
} else {
Get.put(creator());
}
}
return super.onEnter();
}
@override
Future onExit() async {
if (Get.isRegistered<T>()) {
await Get.delete<T>();
}
return super.onExit();
}
}
Then use it like this:
QRoute(
path: '/name',
middleware: [
ControllerRegister(MainController.new),
ControllerRegister(CartController.new),
],
)
@SchabanBo Thanks a lot for your fast answer and sloved my issue If possible, it should be separated from the middleware part in the next version
hello dear @SchabanBo Thanks a lot for this excellent flutter router navigator For switch routing from Getx to Qlevar router, I need one solution or feature I have gone through all the issues successfully The only problem is bindings in getx