[英]Flutter GetX controller not dispose on bottom sheet
您好,我正在创建一个底部工作表作为无状态小部件,并且我正在使用 GetXController,
如果我使用 Get.bottomsheet 创建底部工作表,controller 正在发布,而我关闭工作表是正确的,但我无法增加底部工作表的高度。
如果我使用 flutter 内置的 showModalBottomSheet 创建底部工作表,我可以增加底部工作表的高度但是 controller 在我关闭时没有释放,下面是代码,
我需要增加底部工作表的高度,并在关闭底部工作表时释放 controller。
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"); } }
您可以使用 Get.bottomsheet 这种方式根据您的需要设置高度:
Get.bottomSheet(
isScrollControlled: true,
Container(
height: 600, //specify your height here
child: HomePage(),
),
);
你可以给你想要的容器高度,它会用你在容器高度中提供的高度打开它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.