apptomate_custom_snackbar 0.0.2
apptomate_custom_snackbar: ^0.0.2 copied to clipboard
CustomSnackbar is a highly customizable and reusable Snackbar implementation for Flutter applications.
example/lib/main.dart
import 'package:apptomate_custom_snackbar/apptomate_custom_snackbar.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const CustomSnackbarWidget(),
);
}
}
class CustomSnackbarWidget extends StatelessWidget {
const CustomSnackbarWidget({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("Enhanced Snackbar")),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () => _showSuccessSnackbar(context),
child: const Text("Success Snackbar"),
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () => _showErrorSnackbar(context),
child: const Text("Error Snackbar"),
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () => _showProgressSnackbar(context),
child: const Text("Progress Snackbar"),
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () => _showMultilineSnackbar(context),
child: const Text("Multiline Snackbar"),
),
],
),
),
);
}
void _showSuccessSnackbar(BuildContext context) {
CustomSnackbar.show(
context,
message: "Operation completed successfully!",
backgroundColor: Colors.green,
icon: Icons.check_circle,
duration: const Duration(seconds: 2),
showCloseIcon: true,
showBorder: true,
borderColor: Colors.green.shade700,
);
}
void _showErrorSnackbar(BuildContext context) {
CustomSnackbar.show(
context,
message: "Error: Unable to complete operation",
backgroundColor: Colors.red,
icon: Icons.error_outline,
textColor: Colors.white,
duration: const Duration(seconds: 4),
action: SnackBarAction(
label: "Retry",
textColor: Colors.yellow,
onPressed: () {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
_showSuccessSnackbar(context);
},
),
);
}
void _showProgressSnackbar(BuildContext context) {
CustomSnackbar.show(
context,
message: "Processing your request...",
backgroundColor: Colors.blue,
icon: Icons.hourglass_top,
showProgressIndicator: true,
duration: const Duration(seconds: 3),
);
}
void _showMultilineSnackbar(BuildContext context) {
CustomSnackbar.show(
context,
message: "This is a longer message that will wrap to multiple lines to demonstrate the multiline capability of our enhanced snackbar component.",
backgroundColor: Colors.purple,
icon: Icons.info_outline,
multiline: true,
duration: const Duration(seconds: 5),
showCloseIcon: true,
);
}
}