getx
getx copied to clipboard
Getx Controller is not releasing if showModalBottomSheet to create Bottom sheet
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 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 cool, it is working Thanks for the quick response.
@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");
});
}
}