Flutter – Creating Bottomsheet GetX Library
Last Updated :
07 Apr, 2025
Bottomsheets are the sheets displayed at the bottom to show any content that we want to display. Normally, when we create a bottomsheet, the syntax for creating it is long, and it also uses context. To avoid this, we can create a bottom sheet with simple code with the help of the GetX library. We can create using syntax Get.bottomsheet() in Stateless widget also, and there is no necessity to use Stateful widget for creating bottomsheet. So GetX is very powerful in so many ways, and it helps us a lot in the development.
Follow the below steps to create a bottomsheet using GetX
Step 1 : Create a new Flutter Application
Create a new Flutter application using the command Prompt. To create a new app, write the below command and run it.
flutter create app_name
To know more about it refer this article: Creating a Simple Application in Flutter
Step 2 : Adding the Dependency
To add the dependency to the pubspec.yaml file, add get as a dependency in the dependencies part of the pubspec.yaml file, as shown below:
Dart
dependencies:
flutter:
sdk: flutter
get: ^4.7.2
Now run the below command in the terminal.
flutter pub get
Or
Run the below command in the terminal.
flutter pub add http get
Step 3 : Import dependencies
Import the material file using the following statement in the newly created file.
import 'package:flutter/material.dart';
Import the below files for the working of the application.
import 'package:get/get.dart';
Step 4 : Working with main.dart
But, before going to code part, we need to discuss about Constructor and Propertoes of Get.bottomSheet().
Constructor of Get.bottomSheet() :
Future<T?> bottomSheet<T>(Widget bottomsheet,
{
Color? backgroundColor,
double? elevation,
bool persistent = true,
ShapeBorder? shape,
Clip? clipBehavior,
Color? barrierColor,
bool? ignoreSafeArea,
bool isScrollControlled = false,
bool useRootNavigator = false,
bool isDismissible = true,
bool enableDrag = true,
RouteSettings? settings,
Duration? enterBottomSheetDuration,
Duration? exitBottomSheetDuration
})
properties of Get.bottomSheet():
Property
| Description
|
---|
backgroundColor
| The background color of the bottom sheet.
|
shape
| The shape provided to the bottom sheet.
|
barrierColor
| The barrier color displayed when bottomsheet is opened.
|
isDismissible
| When we want to close the bottomsheet by clicking outside of bottomsheet then its value should be true else false.
|
enableDrag
| If it is set false then we cannot drag bottomsheet. By default, it is set to true.
|
main.dart:
Dart
import 'package:flutter/material.dart';
// Importing GetX package for state management and routing.
import 'package:get/get.dart';
void main() {
// Entry point of the application.
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// The root widget of the application.
@override
Widget build(BuildContext context) {
return GetMaterialApp(
// Using GetMaterialApp instead of MaterialApp for GetX features.
title: 'Bottomsheet',
theme: ThemeData(
primarySwatch: Colors.blue, // Setting the primary theme color.
),
home: HomePage(), // Setting the default home page of the app.
debugShowCheckedModeBanner: false, // Hides the debug banner.
);
}
}
class HomePage extends StatelessWidget {
// The main screen of the application.
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('GeeksforGeeks Bottomsheet'), // Title of the app bar.
backgroundColor: Colors.green[400], // Background color of the app bar.
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center, // Centering the column's children.
children: [
ElevatedButton(
child: Text('Show bottomsheet'), // Button text.
onPressed: () {
// Action to perform when the button is pressed.
Get.bottomSheet(
// Displays a bottom sheet using GetX.
Container(
// Container for the bottom sheet content.
height: 150, // Fixed height of the bottom sheet.
color: Colors.greenAccent, // Background color of the bottom sheet.
child: Column(
// Column to arrange text widgets vertically.
children: [
Text('Hii 1', textScaleFactor: 2), // Enlarged text.
Text('Hii 2', textScaleFactor: 2),
Text('Hii 3', textScaleFactor: 2),
Text('Hii 4', textScaleFactor: 2),
],
),
),
barrierColor: Colors.red[50], // Color of the barrier (scrim) behind the bottom sheet.
isDismissible: false, // Prevents the bottom sheet from being dismissed by tapping outside.
shape: RoundedRectangleBorder(
// Defines the shape of the bottom sheet.
borderRadius: BorderRadius.circular(35), // Rounded corners with a radius of 35.
side: BorderSide(
// Border settings.
width: 5, // Border width.
color: Colors.black, // Border color.
),
),
enableDrag: false, // Disables dragging to dismiss the bottom sheet.
);
},
),
],
),
),
);
}
}
Explanation:
- The first step is to build an app using GetMaterialApp to include the functionalities of GetX library.
- Provide home as HomePage().
- Create Scaffold and in this, create AppBar and body.
- Create a button inside the body and then write the code to create bottomsheet.
- Get.bottomSheet() can be created without using the context.
- Add some properties to Get.bottomSheet() to make it more beautiful.
Get.bottomSheet without any Border:
Get.bottomSheet(
Container(
height: 150,
color: Colors.greenAccent,
child:Column(
children: [
Text('Hii 1', textScaleFactor: 2),
Text('Hii 2', textScaleFactor: 2),
Text('Hii 3', textScaleFactor: 2),
Text('Hii 4', textScaleFactor: 2),
],
)
),
barrierColor: Colors.red[50],
isDismissible: false,
);
When the above code is executed, the output is:
Get.bottomSheet with Border:
Get.bottomSheet(
// Displays a bottom sheet using GetX.
Container(
// Container for the bottom sheet content.
width: double.infinity, // Full width of the screen.
height: 200, // Fixed height of the bottom sheet.
color:Colors.green, // Background color of the bottom sheet.
child: Column(
// Column to arrange text widgets vertically.
children: [
Text('Hii 1', textScaleFactor: 2), // Enlarged text.
Text('Hii 2', textScaleFactor: 2),
Text('Hii 3', textScaleFactor: 2),
Text('Hii 4', textScaleFactor: 2),
],
),
),
barrierColor: Colors.red[50], // Color of the barrier (scrim) behind the bottom sheet.
isDismissible:false, // Prevents the bottom sheet from being dismissed by tapping outside.
shape: RoundedRectangleBorder(
// Defines the shape of the bottom sheet.
borderRadius: BorderRadius.circular(30), // Rounded corners with a radius of 35.
side: BorderSide(
// Border settings.
width: 2, // Border width.
color: Colors.black, // Border color.
),
),
enableDrag:false, // Disables dragging to dismiss the bottom sheet.
);
When the above code is executed with these properties, the output will be:
Similar Reads
Flutter - Creating Snackbar Using GetX Library
Sometimes, it's very useful to show the message when a certain action takes place in our app. Let's suppose, we have a list of items and we want to delete any item from the list then after deleting those items, some message should be displayed to inform the user that the item has been deleted. If we
2 min read
Bottomsheet in Flutter
We can create bottomsheet in flutter. Basically, we have two types of bottomsheets in material design: Persistent and Modal. Bottomsheets are used when we want to perform actions. There are basically two types of Bottomsheets: Persistent and Modal. Persistent bottomsheet do not hide the screen conte
3 min read
Flutter - BottomSheet Class
Bottom Sheet is one of the popular ways to show various options on the screen. This helps the user to switch to a new screen. You will see this bottom sheet in most of the app to add data or add some information such as address or ticket number. In this article, we are going to see how to implement
7 min read
Flutter - Creating Dialog in using GetX Library
When we want to show anything in the form of the dialog then we can create this Dialog using the GetX library in Flutter. When we normally create a dialog in flutter then it uses context and builder to create a Dialog. This is not a good practice for a developer to create Dialogs using contexts and
3 min read
Flutter - Create Rating Star Bar
In the android application, you need to make a rating bar where user rate your craft. For example, GeeksforGeeks also make this feature for tutorials where users can give ratings to the tutorials. A sample video is given below to get an idea about what we are going to do in this article. [video load
3 min read
Flutter - Creating App Intro Screens
Flutter is known for its easiness to create cross-platform applications. Either it is creating introduction screens for the app or any screen. We got an easy way to create Intros for the app using the intro_slider library of Flutter. In this article, we are going to implement it in the sample app. I
4 min read
Flutter - Custom Bottom Navigation Bar
A bottom navigation bar is a material widget that is present at the bottom of an app for selecting or navigating to different pages of the app. It is usually used in conjunction with a Scaffold, where it is provided as the Scaffold.bottomNavigationBar argument. Though Flutter provides you with the B
9 min read
Floating SnackBar in Flutter
The floating_snackbar in Flutter is used to display a temporary message to users, often as feedback after an action. We know how to show the snack bar in a flutter, but everybody wants the application must look more interactive and user-friendly, that's why we can use animations or new designs in th
3 min read
Creating a Simple Application in Flutter
Flutter is an open-source cross-platform mobile application development SDK created by Google. It is highly user-friendly and builds high-quality mobile applications. The intention behind this article is to guide readers through the process of building an application through Flutter by creating a si
5 min read
Flutter - Create 3D Text
Flutter, developed by Google, has gained immense popularity among developers due to its flexibility and ease of use. With Flutter, we can create stunning user interfaces, including 3D elements. This tutorial will explore how to create 3D text in Flutter step by step using the text_3d library. A samp
5 min read