skip to Main Content

I currently face the problem is one class has two different path, but I only create one class.
I think the problem may be coming after I modify the directory name.
The class has two different path
The class current location

since I face this error:
type ‘MedicineController’ is not a subtype of type ‘MedicineController’ in type cast where
MedicineController is from package:elderly_app/src/Views/Elderly/feature/medicine/medicine_controller.dart
MedicineController is from package:elderly_app/src/views/elderly/feature/medicine/medicine_controller.dart

How to fix it? Thank you.

2

Answers


  1. If you’re using vscode, restarting your dart analysis server should be enough.
    If you’re using JetBrains, you should clear your editor’s cache and then restart the editor.

    Login or Signup to reply.
  2. you have Two classes of same name and have imported both of them so dart can not decide which one to use. To solve this problem there are different methods some of them are:

    1. by using hide keyword:

    Hide the Class which from one file the flutter will use the other one just like below:

    import " package:elderly_app/src/Views/Elderly/feature/medicine/medicine_controller.dart" hide MedicineController; 
    // if you don't want to use the MedicineController from this file or hide it from the other file.
    
    1. using as keyword:
    import " package:elderly_app/src/Views/Elderly/feature/medicine/medicine_controller.dart" as mc; 
    

    then use it like this

    Get.put(mc.MedicineController());
    
    1. using show keyword:
    import " package:elderly_app/src/Views/Elderly/feature/medicine/medicine_controller.dart" show ClassName; 
    

    using the above it will only show ClassName in this file. and all other Classes will be hidden.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search