custom_snackbar_plus 8.0.0
custom_snackbar_plus: ^8.0.0 copied to clipboard
A powerful, intelligent, and customizable notification system for Flutter applications with auto-detection, progress bars, and multiple display modes.
import 'package:custom_snackbar_plus/custom_snackbar_plus.dart'
as custom_snackbar_plus;
import 'package:custom_snackbar_plus/custom_snackbar_plus.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'CustomSnackbar Example',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.black),
scaffoldBackgroundColor: Colors.black,
appBarTheme: const AppBarTheme(
backgroundColor: Colors.black,
foregroundColor: Colors.white,
),
),
home:
const MyHomePage(title: 'CustomSnackbar Demo' , ),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({super.key, required this.title});
final String title;
void _showCustomSnackbar(BuildContext context) {
custom_snackbar_plus.CustomSnackbar.show(
context: context,
label: "This is a custom snackbar example!",
title: "Demo",
actionLabel: "OK",
onAction: () {
// Handle action
},
);
}
void _showMultipleSnackbars(BuildContext context) {
custom_snackbar_plus.CustomSnackbar.show(
context: context,
label: "First notification: Welcome!",
title: "Info",
color: Colors.blue,
svgColor: Colors.blue.shade300,
type: SnackbarType.info,
);
CustomSnackbar.show(
context: context,
label: "Second notification: Warning!",
title: "Warning",
color: Colors.orange,
svgColor: Colors.orange.shade300,
type: SnackbarType.warning,
);
CustomSnackbar.show(
context: context,
label: "Third notification: Success!",
title: "Success",
color: Colors.green,
svgColor: Colors.green.shade300,
type: SnackbarType.success,
);
CustomSnackbar.show(
context: context,
label: "Fourth notification: Error occurred!",
title: "Error",
color: Colors.red,
svgColor: Colors.red.shade300,
type: SnackbarType.error,
);
}
void _showSnackbarWithProgress(BuildContext context) {
custom_snackbar_plus.CustomSnackbar.show(
context: context,
label: "This snackbar shows a progress bar for auto-dismiss.",
title: "Progress Demo",
color: Colors.purple,
svgColor: Colors.purple.shade300,
type: SnackbarType.info,
showProgress: true,
duration: const Duration(seconds: 7),
);
}
void _showAutoMode(BuildContext context) {
// Example 1: Error (should show snackbar)
CustomSnackbar.show(
context: context,
label: "An error occurred in the connection",
mode: NotificationMode.auto,
);
// Example 2: Success (should show snackbar)
Future.delayed(const Duration(seconds: 2), () {
CustomSnackbar.show(
context: context,
label: "Data saved successfully",
mode: NotificationMode.auto,
);
});
// Example 3: Warning (should show banner)
Future.delayed(const Duration(seconds: 4), () {
CustomSnackbar.show(
context: context,
label: "Warning: Battery low",
mode: NotificationMode.auto,
);
});
// Example 4: Info (should show banner)
Future.delayed(const Duration(seconds: 6), () {
CustomSnackbar.show(
context: context,
label: "New information available",
mode: NotificationMode.auto,
);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'Press the button to show CustomSnackbar',
style: TextStyle(color: Colors.white, fontSize: 16),
),
const SizedBox(height: 20),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
foregroundColor: Colors.white,
),
onPressed: () => _showCustomSnackbar(context),
child: const Text('Show Single Snackbar'),
),
const SizedBox(height: 20),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
foregroundColor: Colors.white,
),
onPressed: () => _showMultipleSnackbars(context),
child: const Text('Show Multiple Snackbars'),
),
const SizedBox(height: 20),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
foregroundColor: Colors.white,
),
onPressed: () => _showSnackbarWithProgress(context),
child: const Text('Show Snackbar with Progress'),
),
const SizedBox(height: 20),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
foregroundColor: Colors.white,
),
onPressed: () => _showAutoMode(context),
child: const Text('Show Auto Mode Demo'),
),
],
),
),
);
}
}