3 messageText: This property is
used to specify the message text of the Snackbar this property overrides the
default message text property of the Snackbar.
Get.snackbar(
"this is snackbar", //this is The Defult Snacbar title
"Snackbar Using Getx Librery",
snackPosition: SnackPosition.BOTTOM,
titleText: const Text( //this title text overide the Default Text Above
"this is snackbar title",
style: TextStyle(color: Colors.blue, fontSize: 20),
),
messageText: const Text( //this message overides the
//defaukt message text above
"this is message text",
style: TextStyle(color: Colors.blue, fontSize: 20),
)
);
4: colorText: use this property to specify or change the color of the title text and message text
Get.snackbar(
"this is snackbar", //this is The Defult Snacbar title
"Snackbar Using Getx Librery",
snackPosition: SnackPosition.BOTTOM,
titleText: const Text(
//this title text overide the Default Text Above
"this is snackbar title",
style: TextStyle(color: Colors.blue, fontSize: 20),
),
messageText: const Text(
//this message overides the
//defaukt message text above
"this is message text",
style: TextStyle(color: Colors.blue, fontSize: 20),
),
colorText: Colors.red, //used to chnage color of text
);
5: backgroundColor: use this property to change
the background color of the Snackbar
Get.snackbar(
"this is snackbar", //this is The Defult Snacbar title
"Snackbar Using Getx Librery",
snackPosition: SnackPosition.BOTTOM,
titleText: const Text(
//this title text overide the Default Text Above
"this is snackbar title",
style: TextStyle(color: Colors.blue, fontSize: 20),
),
messageText: const Text(
//this message overides the
//defaukt message text above
"this is message text",
style: TextStyle(color: Colors.blue, fontSize: 20),
),
colorText: Colors.red, //used to chnage color of text
backgroundColor: Colors.black,
);
6: borderRadius: Use this property to add border-radius to Snackbar
Get.snackbar(
"this is snackbar", //this is The Defult Snacbar title
"Snackbar Using Getx Librery",
snackPosition: SnackPosition.BOTTOM,
titleText: const Text(
//this title text overide the Default Text Above
"this is snackbar title",
style: TextStyle(color: Colors.blue, fontSize: 20),
),
messageText: const Text(
//this message overides the
//defaukt message text above
"this is message text",
style: TextStyle(color: Colors.blue, fontSize: 20),
),
colorText: Colors.red, //used to chnage color of text
backgroundColor: Colors.black,
borderRadius: 30,
);
7:Margin: use this property to add margin to our Snackbar
Get.snackbar(
"this is snackbar", //this is The Defult Snacbar title
"Snackbar Using Getx Librery",
snackPosition: SnackPosition.BOTTOM,
titleText: const Text(
//this title text overide the Default Text Above
"this is snackbar title",
style: TextStyle(color: Colors.blue, fontSize: 20),
),
messageText: const Text(
//this message overides the
//defaukt message text above
"this is message text",
style: TextStyle(color: Colors.blue, fontSize: 20),
),
colorText: Colors.red, //used to chnage color of text
backgroundColor: Colors.black,
borderRadius: 30,
margin: EdgeInsets.all(10),
);
8: Maxwidth: use Maxwidth- property to add Maximum width to Snackbar
Get.snackbar(
"this is snackbar", //this is The Defult Snacbar title
"Snackbar Using Getx Librery",
snackPosition: SnackPosition.BOTTOM,
titleText: const Text(
//this title text overide the Default Text Above
"this is snackbar title",
style: TextStyle(color: Colors.blue, fontSize: 20),
),
messageText: const Text(
//this message overides the
//defaukt message text above
"this is message text",
style: TextStyle(color: Colors.blue, fontSize: 20),
),
colorText: Colors.red, //used to chnage color of text
backgroundColor: Colors.black,
borderRadius: 30,
margin: EdgeInsets.all(10),
maxWidth: 100,
);
9: animation-duration: use this property to add the Duration to Snackbar.
Get.snackbar(
"this is snackbar", //this is The Defult Snacbar title
"Snackbar Using Getx Librery",
snackPosition: SnackPosition.BOTTOM,
titleText: const Text(
//this title text overide the Default Text Above
"this is snackbar title",
style: TextStyle(color: Colors.blue, fontSize: 20),
),
messageText: const Text(
//this message overides the
//defaukt message text above
"this is message text",
style: TextStyle(color: Colors.blue, fontSize: 20),
),
colorText: Colors.red, //used to chnage color of text
backgroundColor: Colors.black,
borderRadius: 30,
margin: EdgeInsets.all(10),
maxWidth: 100,
animationDuration: Duration(microseconds: 200),
);
10: background gradient: you can use Linear
Gradient as a background gradient of Snackbar. if you specify background
Gradient BackgroundColors do not have any effect. which means background
gradient overrides Background Color Properties
Get.snackbar(
"this is snackbar", //this is The Defult Snacbar title
"Snackbar Using Getx Librery",
snackPosition: SnackPosition.BOTTOM,
titleText: const Text(
//this title text overide the Default Text Above
"this is snackbar title",
style: TextStyle(color: Colors.blue, fontSize: 20),
),
messageText: const Text(
//this message overides the
//defaukt message text above
"this is message text",
style: TextStyle(color: Colors.blue, fontSize: 20),
),
colorText: Colors.red, //used to chnage color of text
backgroundColor: Colors.black,
borderRadius: 30,
margin: EdgeInsets.all(10),
maxWidth: 100,
animationDuration: Duration(microseconds: 200),
backgroundGradient: LinearGradient(colors: [Colors.red,Colors.black]),
);
11: border-color and Border width: whenEver you use
borderColor you must specify the Border width also otherwise you got an
error
borderColor: Colors.green,
borderWidth: 12,
12: BoxShadow- This property is used to create a shadow for our Snackbar.
Get.snackbar(
"this is snackbar", //this is The Defult Snacbar title
"Snackbar Using Getx Librery",
snackPosition: SnackPosition.BOTTOM,
titleText: const Text(
//this title text overide the Default Text Above
"this is snackbar title",
style: TextStyle(color: Colors.blue, fontSize: 20),
),
messageText: const Text(
//this message overides the
//defaukt message text above
"this is message text",
style: TextStyle(color: Colors.blue, fontSize: 20),
),
colorText: Colors.red, //used to chnage color of text
backgroundColor: Colors.black,
borderRadius: 30,
margin: EdgeInsets.all(10),
maxWidth: 100,
animationDuration: Duration(microseconds: 200),
backgroundGradient: LinearGradient(colors: [Colors.red,Colors.black]),
borderColor: Colors.green,
borderWidth: 12,
boxShadows: [
const BoxShadow(
color: Colors.pink,
offset: Offset(30,30),
blurRadius: 10,
spreadRadius: 8,
)
]
);
13: is dismissable and DismissDirection: You can
add Dismiss properties to Snackbar, in order to make it dismissable to the
specified Directions, like this isDismissible: true, dismissDirection: DismissDirection.horizontal
Get.snackbar(
"this is snackbar", //this is The Defult Snacbar title
"Snackbar Using Getx Librery",
snackPosition: SnackPosition.BOTTOM,
titleText: const Text(
//this title text overide the Default Text Above
"this is snackbar title",
style: TextStyle(color: Colors.blue, fontSize: 20),
),
messageText: const Text(
//this message overides the
//defaukt message text above
"this is message text",
style: TextStyle(color: Colors.blue, fontSize: 20),
),
colorText: Colors.red, //used to chnage color of text
backgroundColor: Colors.black,
borderRadius: 30,
margin: EdgeInsets.all(10),
maxWidth: 100,
animationDuration: Duration(microseconds: 200),
backgroundGradient: LinearGradient(colors: [Colors.red,Colors.black]),
borderColor: Colors.green,
borderWidth: 12,
boxShadows: [
const BoxShadow(
color: Colors.pink,
offset: Offset(30,30),
blurRadius: 10,
spreadRadius: 8,
)
],
isDismissible: true,
dismissDirection: DismissDirection.horizontal
);
14: forwardAnimationCurve: you can add animation
to Snackbar using forwardAnimationCurve and add Duration to decide how much
second Snackbar waits.
Get.snackbar(
"this is snackbar", //this is The Defult Snacbar title
"Snackbar Using Getx Librery",
snackPosition: SnackPosition.BOTTOM,
titleText: const Text(
//this title text overide the Default Text Above
"this is snackbar title",
style: TextStyle(color: Colors.blue, fontSize: 20),
),
messageText: const Text(
//this message overides the
//defaukt message text above
"this is message text",
style: TextStyle(color: Colors.blue, fontSize: 20),
),
colorText: Colors.red, //used to chnage color of text
backgroundColor: Colors.black,
borderRadius: 30,
margin: EdgeInsets.all(10),
maxWidth: 100,
animationDuration: Duration(microseconds: 200),
backgroundGradient: LinearGradient(colors: [Colors.red,Colors.black]),
borderColor: Colors.green,
borderWidth: 12,
boxShadows: [
const BoxShadow(
color: Colors.pink,
offset: Offset(30,30),
blurRadius: 10,
spreadRadius: 8,
)
],
isDismissible: true,
dismissDirection: DismissDirection.horizontal,
forwardAnimationCurve: Curves.bounceIn,
duration: Duration(microseconds: 100),
);
15: Icon and Mian Button: you can add Icon and
TextButton as a leading and trailing of Snackbar;
Get.snackbar(
"this is snackbar", //this is The Defult Snacbar title
"Snackbar Using Getx Librery",
snackPosition: SnackPosition.BOTTOM,
titleText: const Text(
//this title text overide the Default Text Above
"this is snackbar title",
style: TextStyle(color: Colors.blue, fontSize: 20),
),
messageText: const Text(
//this message overides the
//defaukt message text above
"this is message text",
style: TextStyle(color: Colors.blue, fontSize: 20),
),
colorText: Colors.red, //used to chnage color of text
backgroundColor: Colors.black,
borderRadius: 30,
margin: EdgeInsets.all(10),
maxWidth: 100,
animationDuration: Duration(microseconds: 200),
backgroundGradient: LinearGradient(colors: [Colors.red,Colors.black]),
borderColor: Colors.green,
borderWidth: 12,
boxShadows: [
const BoxShadow(
color: Colors.pink,
offset: Offset(30,30),
blurRadius: 10,
spreadRadius: 8,
)
],
isDismissible: true,
dismissDirection: DismissDirection.horizontal,
forwardAnimationCurve: Curves.bounceIn,
duration: Duration(microseconds: 100),
icon: const Icon(
Icons.send, color: Colors.white, ),
shouldIconPulse: false,
mainButton: TextButton(onPressed: (){}, child: const Text("data")),
//icon and mainButton is used to add icob and Button to snack Bar
);
16: onTab: Snackbar has onTab properties that we can use to handle when we pressed the Snackbar.
Get.snackbar(
"this is snackbar", //this is The Defult Snacbar title
"Snackbar Using Getx Librery",
snackPosition: SnackPosition.BOTTOM,
titleText: const Text(
//this title text overide the Default Text Above
"this is snackbar title",
style: TextStyle(color: Colors.blue, fontSize: 20),
),
messageText: const Text(
//this message overides the
//defaukt message text above
"this is message text",
style: TextStyle(color: Colors.blue, fontSize: 20),
),
colorText: Colors.red, //used to chnage color of text
backgroundColor: Colors.black,
borderRadius: 30,
margin: EdgeInsets.all(10),
maxWidth: 100,
animationDuration: Duration(microseconds: 200),
backgroundGradient: LinearGradient(colors: [Colors.red,Colors.black]),
borderColor: Colors.green,
borderWidth: 12,
boxShadows: [
const BoxShadow(
color: Colors.pink,
offset: Offset(30,30),
blurRadius: 10,
spreadRadius: 8,
)
],
isDismissible: true,
dismissDirection: DismissDirection.horizontal,
forwardAnimationCurve: Curves.bounceIn,
duration: Duration(microseconds: 100),
icon: const Icon(
Icons.send, color: Colors.white, ),
shouldIconPulse: false,
mainButton: TextButton(onPressed: (){}, child: const Text("data")),
onTap: (Value){
print("Snackbar is Tabbed");
}
);
Here is a full source code of Snackbar Using Getx Library, or watch the video Here
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/get_navigation/get_navigation.dart';
void main() {
runApp(
SnackBar(),
);
}
class SnackBar extends StatefulWidget {
SnackBar({Key? key}) : super(key: key);
@override
State<SnackBar> createState() => _SnackBarState();
}
class _SnackBarState extends State<SnackBar> {
@override
Widget build(BuildContext context) {
return GetMaterialApp(
title: "GetX Tutorials",
home: Scaffold(
appBar: AppBar(
title: Text("Getx"),
),
body: Column(
children: [
ElevatedButton(
onPressed: () {
Get.snackbar(
"this is snackbar", //this is The Defult Snacbar title
"Snackbar Using Getx Librery",
snackPosition: SnackPosition.BOTTOM,
titleText: const Text(
//this title text overide the Default Text Above
"this is snackbar title",
style: TextStyle(color: Colors.blue, fontSize: 20),
),
messageText: const Text(
//this message overides the
//defaukt message text above
"this is message text",
style: TextStyle(color: Colors.blue, fontSize: 20),
),
colorText: Colors.red, //used to chnage color of text
backgroundColor: Colors.black,
borderRadius: 30,
margin: EdgeInsets.all(10),
maxWidth: 100,
animationDuration: Duration(microseconds: 200),
backgroundGradient:
LinearGradient(colors: [Colors.red, Colors.black]),
borderColor: Colors.green,
borderWidth: 12,
boxShadows: [
const BoxShadow(
color: Colors.pink,
offset: Offset(30, 30),
blurRadius: 10,
spreadRadius: 8,
)
],
isDismissible: true,
dismissDirection: DismissDirection.horizontal,
forwardAnimationCurve: Curves.bounceIn,
duration: Duration(microseconds: 100),
icon: const Icon(
Icons.send,
color: Colors.white,
),
shouldIconPulse: false,
mainButton:
TextButton(onPressed: () {}, child: const Text("data")),
onTap: (Value) {
print("Snackbar is Tabbed");
});
},
child: const Text("showsnackBar"),
)
],
),
),
);
}
}
Leave a Comment