jonataslaw / getx

Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
MIT License
10.21k stars 1.6k forks source link

breakpoints not working in getview #2767

Open DenizUlucan opened 1 year ago

DenizUlucan commented 1 year ago

hello, I am trying to migrate my project to getx mvc architecture, most of it is completed but breakpoints are not working in getview has anyone encountered this situation? (works inside getxcontroller)

JohnF17 commented 1 year ago

Hello, here's the reason for that don't use GetView for updating your code, that doesn't work, use GetBuilder, GetBuilders are suppposed to update the code whenever its given controller's update method is called example

class  MyController extends GetxController{
    void callingThisMethodToUpdateMyWidget(){
         update();
    }
}

and somewhere in your widget tree where you want updates you use this

return GetBuilder<MyController>(
    //init: Get.put<MyController>(MyController()),
    // assuming you have put your controller bindings you wont have to call [init] but if u haven't uncomment the line above
    builder: (myController){   // the controller reference is given to you
     return Column(
     children: [
           MyWidget(), // Lets say this was the widget you wanted to update
          Text('Hello'),
          TextButton(
               onPressed: (){
                 // Since you have the controller reference given to you by the builder use it like this
                 myController.callingThisMethodToUpdateMyWidget();  // THIS UPDATES THIS WHOLE TREE
               },
               child: const Text('Click here to update MyWidget()')
             )
          ]
     );
     }
);

You can also use obx widgets to listen to changes in observable variables declared like var myVar = true.obs;

GetViews don't update your code and infact that's not what they're supposed to do, they're just there to give you a reference to your controller in stateless widgets while maintaining its const constructor, immutability (if they aren't final) and its statelessness (i'd say), if you look at how they're implemented, it's quite the widget.

abstract class GetView<T> extends StatelessWidget {
  const GetView({Key? key}) : super(key: key);

  final String? tag = null;

  T get controller => GetInstance().find<T>(tag: tag)!;

  @override
  Widget build(BuildContext context);
}

Anyways this might help, this might not, i might be reading your whole issue wrong, i might not, but hey atleast it might help someone, cheers!👍

DenizUlucan commented 1 year ago

hello, first of all thanks for your reply. When I don't use any structure, the breakpoints I set work when the page is first loaded or when I click a button on my page. But after I started using getview and getcontrollers, it stopped working as before. I guess it is due to lazyput and put events. For breakpoint to work, the controller must be created. I don't know if it's normal, it works like this too

Baghdady92 commented 1 year ago

i have same problem never though about it it's from get package lol

JohnF17 commented 1 year ago

Hello to you both, can y'all share a small code snippet and run flutter doctor -v to help debug this issue? thanks