getCoreUtilsCommonSnackbarTemplate function
String
getCoreUtilsCommonSnackbarTemplate(
- String projectName
)
Implementation
String getCoreUtilsCommonSnackbarTemplate(String projectName) {
return '''
import 'package:flutter/material.dart';
import 'package:${projectName}/core/theme/app_colors.dart';
class CommonSnackBar {
static void show(
BuildContext context, {
required String message,
Color backgroundColor = Colors.black,
Duration duration = const Duration(seconds: 3),
SnackBarAction? action,
IconData? icon,
}) {
final bottomSafeArea = MediaQuery.of(context).viewPadding.bottom;
final snackBar = SnackBar(
duration: duration,
behavior: SnackBarBehavior.floating,
backgroundColor: backgroundColor,
margin: EdgeInsets.fromLTRB(
12,
12,
12,
12 + bottomSafeArea, // prevents hiding behind system nav bar
),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
content: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
if (icon != null) ...[
Icon(icon, color: AppColors.primary),
const SizedBox(width: 10),
],
Expanded(
child: Text(
message,
style: const TextStyle(color: Colors.black, fontSize: 14),
),
),
],
),
action: action,
);
final messenger = ScaffoldMessenger.of(context);
messenger
..hideCurrentSnackBar()
..showSnackBar(snackBar);
}
/// Success
static void success(BuildContext context, String message) {
show(
context,
message: message,
backgroundColor: AppColors.background,
icon: Icons.check_circle,
);
}
/// Error
static void error(BuildContext context, String message) {
show(
context,
message: message,
backgroundColor: AppColors.background,
icon: Icons.error,
);
}
/// Info
static void info(BuildContext context, String message) {
show(
context,
message: message,
backgroundColor: AppColors.background,
icon: Icons.info,
);
}
}
''';
}