Flutter - Creating Snackbar Using GetX Library
Last Updated :
14 May, 2021
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 want to undo the action then we can simply do and show the snackbar with some message. Generally, when we create snackbar, then it uses context for creating snackbar, and also syntax is not so easy. To overcome this problem, we can create Snackbar using GetX with just simple code without using any context.
Follow the below steps to create snackbar using GetX:
- Create a new flutter application with the below command:
flutter create APP_NAME
- Add get package to pubspec.yaml file:

- Import get package in main.dart file:
import 'package:get/get.dart';
- For creating an app, use GetMaterialApp instead of MaterialApp because we are using GetX library.
- After the creation of the app, create a button in the center.
- After that, create Snackbar using Get.snackbar(title, message);
- Provide the title and message to the snackbar.
- We can add some extra beauty to this snackbar like background color, text color, snackbar duration, snackbarPosition, onTap() property, etc.
main.dart file:
Dart
import 'package:flutter/material.dart';
import 'package:get/get.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return GetMaterialApp(
title: 'Scaffold demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
debugShowCheckedModeBanner: false,
);
}
}
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('GeeksforGeeks Scaffold'),
centerTitle: true,
backgroundColor: Colors.green,
),
body: Center(
child: ElevatedButton(
child: Text('Open Snackbar'),
onPressed: (){
Get.snackbar(
"GeeksforGeeks",
"Hello everyone",
icon: Icon(Icons.person, color: Colors.white),
snackPosition: SnackPosition.BOTTOM,
);
},
),
),
);
}
}
Output:
Get.snackbar(
"GeeksforGeeks",
"Hello everyone",
icon: Icon(Icons.person, color: Colors.white),
snackPosition: SnackPosition.BOTTOM,
backgroundColor: Colors.green,
);
If we run our app with the above properties then the output will be:

Get.snackbar(
"GeeksforGeeks",
"Hello everyone",
icon: Icon(Icons.person, color: Colors.white),
snackPosition: SnackPosition.BOTTOM,
backgroundColor: Colors.green,
borderRadius: 20,
margin: EdgeInsets.all(15),
colorText: Colors.white,
duration: Duration(seconds: 4),
isDismissible: true,
dismissDirection: SnackDismissDirection.HORIZONTAL,
forwardAnimationCurve: Curves.easeOutBack,
);
If we run with the above properties, the output will be:
Similar Reads
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 - Creating Bottomsheet GetX Library 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 ca
5 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 the
3 min read
Flutter - GetX State Management Library GetX is a fast, stable, and light state management library in Flutter that simplifies the process of managing and updating the state of your application. It is an alternative to other state management libraries in Flutter like MobX, BLoC, Redux, Provider, etc. GetX is also a powerful micro framework
5 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.
4 min read