Search code examples
flutterdependencieswidgetflutter-getx

GetxController is not subtype of GetxController


I am currently working on Ecommerce App in which i put the bottom navigation at homepage with badge on each icon ,Here when i put cartItems counter badge on CartIcon with dependency injection of cartcontroller on homepage(I have tried both methods using Getbuilder and Obx) ,but as i also using bottom navigation have to navigate my app through cartscreen which also has cartcontroller dependency the following error shows up .it's like i can't put the same controller in parent and child widget in widgets tree. PS:I have also tried Get.find() for cartscreen. Here is the error:

════════ Exception caught by widgets library ═══════════════════════════════════
The following _CastError was thrown building Builder:

    type 'CartController' is not a subtype of type 'CartController' in type cast where
    CartController is from sourcepath/controllers/cartController.dart
    sourcepath/controllers/cartcontroller.dart:1
    CartController is from sourcepath/controllers/cartcontroller.dart

Solution

  • So far i have understood that you have two different controllers One is cartController and other one is cartcontroller (note the camel casing) so technically you cannot cast them together. Please check that in your code.