mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-08-24 20:22:27 +00:00
Add AppSnackBarsBuildContextExtension
for displaying success and failure snack bars in the app.
This commit is contained in:
56
lib/utils/extension/app_snack_bar.dart
Normal file
56
lib/utils/extension/app_snack_bar.dart
Normal file
@ -0,0 +1,56 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||
|
||||
extension AppSnackBarsBuildContextExtension on BuildContext {
|
||||
void showSuccessSnackbar(String message) {
|
||||
ScaffoldMessenger.of(this).showSnackBar(
|
||||
_makeSnackbar(
|
||||
message: message,
|
||||
icon: Icons.check_circle,
|
||||
backgroundColor: Colors.green,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void showFailureSnackbar(String message) {
|
||||
ScaffoldMessenger.of(this).showSnackBar(
|
||||
_makeSnackbar(
|
||||
message: message,
|
||||
icon: Icons.error,
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
SnackBar _makeSnackbar({
|
||||
required String message,
|
||||
required Color backgroundColor,
|
||||
required IconData icon,
|
||||
}) {
|
||||
return SnackBar(
|
||||
content: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
spacing: 8,
|
||||
children: [
|
||||
Icon(icon, color: Colors.white),
|
||||
Text(
|
||||
message,
|
||||
style: textTheme.bodyMedium?.copyWith(
|
||||
color: ColorsManager.whiteColors,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
backgroundColor: backgroundColor,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12.0),
|
||||
),
|
||||
margin: const EdgeInsetsDirectional.symmetric(
|
||||
horizontal: 92,
|
||||
vertical: 32,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user