getx icon indicating copy to clipboard operation
getx copied to clipboard

Getx Controller is not releasing if showModalBottomSheet to create Bottom sheet

Open csramkumar opened this issue 2 years ago • 2 comments

I am creating a bottom sheet as stateless widget and I am using a GetXController,

if I use Get.bottomsheet to create bottom sheet, controller is getting release while I dismiss the sheet which is correct but I am not able to increase the height of bottom sheet.

if I use flutter inbuilt showModalBottomSheet to create bottom sheet, I am able to increase the height of bottom Sheet but controller is not releasing while I dismiss, below is the code,

I need to increase the bottom sheet height as well release the controller on dismissing bottom sheet .

Class MainPage extends StatelessWidget {

   return TextButton(onPressed: () {
       
     // if we use like this on dismissing homepage, controller is also releasing, the problem of using this not able to adjust the height of bottom sheet using get
     Get.bottomSheet(HomePage());

   // if we use like this on dismissing homepage, controller is not releasing, by this approach we can control the height of bottom sheet but controller is not releasing    showModalBottomSheet(
     context: context,
     builder: (context) => HomePage(),
     enableDrag: false,
    );  
 });
  }

class GetC extends GetxController { }

class HomePage extends StatelessWidget {   @override   Widget build(BuildContext context) {
    final GetC controller = Get.put(GetC());
    return Text("Controller not releasing");   } }

csramkumar avatar Jul 03 '22 12:07 csramkumar

@csramkumar it will be release if you wrap Text by GetBuider.

class GetC extends GetxController {}

class HomePage extends StatelessWidget { const HomePage({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return GetBuilder<GetC>( init: GetC(), builder: (GetC c) { return const Text("Controller not releasing"); }); } }

Shawnli1201 avatar Jul 05 '22 05:07 Shawnli1201

@Shawnli1201 cool, it is working Thanks for the quick response.

csramkumar avatar Jul 06 '22 05:07 csramkumar

@csramkumar it will be release if you wrap Text by GetBuider.

class GetC extends GetxController {}

class HomePage extends StatelessWidget { const HomePage({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return GetBuilder( init: GetC(), builder: (GetC c) { return const Text("Controller not releasing"); }); } }

Hey @Shawnli1201, thank you for saving me 1 hr. Formatted code:

class HomePage extends StatelessWidget {
    const HomePage({Key? key}) : super(key: key);
    @override
    Widget build(BuildContext context) {
        return GetBuilder<GetC>(
                init: GetC(),
                builder: (GetC controller) {
                    return const Text("Controller not releasing");
        });
    }
}

princ3od avatar Mar 09 '23 09:03 princ3od