Snackbar using GetX

 import "package:flutter/material.dart";

import "package:get/get.dart";

void main()
{
runApp(const MyApp());
}
class MyApp extends StatelessWidget
{
const MyApp({super.key});

@override
Widget build(BuildContext context) {
return GetMaterialApp(
title: "Snack bar using Getx",
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.grey,
),
home: const PracticeSnackbar(),
);
}
}
class PracticeSnackbar extends StatelessWidget
{
const PracticeSnackbar({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Snackbar using GetX"),
centerTitle: true,
backgroundColor: Colors.grey,
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
ElevatedButton(
onPressed: () {
Get.snackbar(
"Snackbar Title",
"This will be Snackbar Message",
/// By default, Snackbar will display at Top Position
snackPosition: SnackPosition.BOTTOM,
// titleText: const Text("Another Text", style: TextStyle(fontWeight: FontWeight.bold),),
// messageText: const Text("Another Message"),
// colorText: Colors.white,
// backgroundColor: Colors.black,
borderRadius: 30.0,
margin: const EdgeInsets.all(10),
// maxWidth: 100.0,
// animationDuration: const Duration(milliseconds: 3000),
backgroundColor: Colors.red,
backgroundGradient: const LinearGradient(
colors: [Colors.red, Colors.green,],
),
/// While using borderColor ensure you are using borderWidth otherwise error
/// will be generated
// borderColor: Colors.purple, /// This two properties must be
// borderWidth: 4, /// declared simultaneously

boxShadows: [
const BoxShadow(
color: Colors.yellow,
offset: Offset(30, 50),
spreadRadius: 20.0,
blurRadius: 8,
),
],
isDismissible: true,
// dismissDirection: SnackDismissDirection.HORIZONTAL,
forwardAnimationCurve: Curves.bounceInOut,
duration: const Duration(milliseconds: 5000),
icon: const Icon(
Icons.send,
color: Colors.white,
),
shouldIconPulse: false, /// Here Animation of Icon will stop
leftBarIndicatorColor: Colors.grey,
mainButton: TextButton(
onPressed: () {},
style: TextButton.styleFrom(
backgroundColor: Colors.grey,
),
child: const Text("Retry",
style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
),
),
onTap: (value) {
print("Snackbar Clicked!");
},
/// When the Button is clicked and Snackbar is opened at that time background of
/// screen is blurred using overlayBlur and we can set screen color at that time of
/// snackbar appearing using overlayColor as shown below:
// overlayBlur: 5,
// overlayColor: Colors.grey,
padding: const EdgeInsets.all(20.0),
showProgressIndicator: true,
progressIndicatorBackgroundColor: Colors.cyanAccent,
progressIndicatorValueColor: const AlwaysStoppedAnimation<Color>(Colors.blue),
reverseAnimationCurve: Curves.bounceInOut,
///We can see the status of Snackbar using snackbarStatus Property as shown below
snackbarStatus: (status) {
print(status);
},
/// When we are using the userInputForm, then all the property declared above like
/// mainButton, icon etc will be hidden
userInputForm: Form(
child: TextFormField(),
),
);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
fixedSize: const Size(300.0, 50.0),
),
child: const Text("Show Snackbar",
style: TextStyle(fontWeight: FontWeight.bold, color: Colors.white, fontSize: 20.0),
),
),
],
),
),
);
}
}

Comments

Popular posts from this blog

Second GET API Calling with Bloc simple Example in Flutter

Stack Container Scrollable Card widget UI with Custom Widget

Pagination with Bloc Pattern in Flutter