What is GetX BottomSheet?
GetX provides a context‑free way to show bottom sheets – modal or persistent – anywhere in your app. Unlike Flutter's native showModalBottomSheet, you don't need a BuildContext. This makes it ideal for showing actions, forms, or additional content from controllers, services, or any Dart class. You can also await the result and control whether the user can dismiss it by tapping outside.
Basic Usage: Get.bottomSheet
Key Parameters
- backgroundColor – Background color of the sheet (default is white).
- barrierColor – Color of the overlay behind the sheet.
- isScrollControlled – Whether the sheet can expand to full screen (default false). When true, the sheet can take any height, even beyond the safe area.
- enableDrag – Whether the user can drag to dismiss (default true).
- isDismissible – Whether tapping outside dismisses the sheet (default true).
- elevation – Elevation of the sheet (default 4.0).
- shape – Custom shape (e.g., RoundedRectangleBorder).
- clipBehavior – How to clip the sheet (default Clip.none).
- settings – Route settings.
- enterBottomSheetDuration – Animation duration for entering (default 250ms).
- exitBottomSheetDuration – Animation duration for exiting (default 250ms).
- ignoreSafeArea – Whether to ignore safe area (default false).
- useRootNavigator – Whether to use the root navigator (default false).
Custom Height & Scrollable Content
By default, the bottom sheet has a fixed height. To make it scrollable or full screen, use isScrollControlled: true.
Full‑Screen Bottom Sheet
Combine isScrollControlled: true with height: double.infinity to fill the screen.
Returning Values
You can await the bottom sheet and return a value using Get.back(result: value).
Persistent Bottom Sheets
By default, bottom sheets are modal (they block interaction with the underlying content). You can create a persistent bottom sheet that stays open while allowing interaction with the background by using isDismissible: false and enableDrag: false.
Customizing Shape & Animation
Using with Controllers
Since Get.bottomSheet doesn't need a context, you can call it directly from a controller or service.
Comparison: GetX vs Native BottomSheet
| Aspect | GetX BottomSheet | Native showModalBottomSheet |
|---|---|---|
| Requires BuildContext | No | Yes |
| Can be called from controller | Yes | No (needs context) |
| Return value support | Yes (Future) | Yes (Future) |
| Persistent sheet | Yes (isDismissible: false) | No (always modal) |
| Custom shape | Yes | Yes |
| Animation control | Yes | Yes |
Best Practices
- Use
isScrollControlledfor scrollable content – Avoid overflow issues. - Provide a clear close action – Include a close button or gesture, especially when
isDismissibleis false. - Return values when applicable – Let callers know what was selected.
- Keep the sheet height appropriate – Not too tall, not too short, unless full screen is intended.
- Test on small screens – Ensure content fits and is scrollable if needed.
Common Mistakes
- ❌ Forgetting to handle return values – The future may be ignored; but if you need the result, await it.
- ❌ Setting
isScrollControlledwithout adjusting height – The sheet may not be visible if height is too small. - ❌ Using
Get.bottomSheetwithoutGetMaterialApp– Won't work. - ❌ Making the sheet non‑dismissible without a close button – Users may get stuck. ✅ Always provide a way to close.
Conclusion
GetX bottom sheets provide a simple, context‑free API for showing modal and persistent sheets. With extensive customization options and the ability to return values, they are perfect for actions, filters, forms, and more in your Flutter app.