Add Bindings to BottomSheets & Dialogs soon? Like Get.bottomSheet(binding: Binding()); #1167
Replies: 3 comments 1 reply
-
@nemoryoliver Hi, I fully agree with this idea. Could you help me with that, how do you currently link controllers to the bottom sheet? |
Beta Was this translation helpful? Give feedback.
-
Guys I created a structure to be able to use bindings for bottom sheets, dialogs, custom views etc. Let me explain my structure, it can be useful for others: Implementation
typedef BindingCreator<S extends Bindings> = S Function();
abstract class BaseCustomWidget<Binding extends Bindings, Controller> extends GetView<Controller> {
final BindingCreator<Binding>? bindingCreator;
BaseCustomWidget({required this.bindingCreator});
Widget view();
@nonVirtual
Widget build(BuildContext context) {
_createBinding();
return body();
}
void _createBinding() {
Binding? binding = bindingCreator?.call();
binding?.dependencies();
}
} UsageLet's say I have a custom widget that extends class CustomTextWidget extends BaseCustomWidget<CustomTextBinding, CustomTextController> {
CustomTextWidget({required BindingCreator<CustomTextBinding>? bindingCreator}) : super(bindingCreator: bindingCreator);
Widget view() {
return ....;
}
} For example, I use this as below: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: [
CustomTextWidget(bindingCreator: () => CustomTextBinding()),
],
),
); You can create bottom sheets or dialogs and extend Get.bottomSheet(
MyBottomSheet(bindingCreator: () => MyBottomSheetBinding()),
isScrollControlled: true,
backgroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(degree),
topRight: Radius.circular(degree),
),
),
); |
Beta Was this translation helpful? Give feedback.
-
I have tried this. it is working fine for me. After edited the code please do Hot Restart the app. Then only it will work.
|
Beta Was this translation helpful? Give feedback.
-
I use a lot of bottom sheets in my app to keep the UX reachable using one hand. so I wish there's the same function of a Page to a BottomSheet where you can bind controllers.
Beta Was this translation helpful? Give feedback.
All reactions