Flutter Custom Message – Flash Message Copy and paste the below code as per your requirements.
awesome_snackbar_content: <latest-package>
import 'package:flutter/material.dart';
import 'package:awesome_snackbar_content/awesome_snackbar_content.dart';
class AweseomSnackBarExample extends StatelessWidget {
const AweseomSnackBarExample({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ElevatedButton(
child: const Text('Show Awesome SnackBar'),
onPressed: () {
final snackBar = SnackBar(
/// need to set following properties for best effect of awesome_snackbar_content
elevation: 0,
behavior: SnackBarBehavior.floating,
backgroundColor: Colors.transparent,
content: AwesomeSnackbarContent(
title: 'On Snap!',
message:
'This is an example error message!',
contentType: ContentType.failure,
),
);
ScaffoldMessenger.of(context)
..hideCurrentSnackBar()
..showSnackBar(snackBar);
},
),
const SizedBox(height: 10),
ElevatedButton(
child: const Text('Show Awesome Material Banner'),
onPressed: () {
final materialBanner = MaterialBanner(
elevation: 0,
backgroundColor: Colors.transparent,
forceActionsBelow: true,
content: AwesomeSnackbarContent(
title: 'Oh Hey!!',
message:
'This is an example error message',
contentType: ContentType.success,
inMaterialBanner: true,
),
actions: const [SizedBox.shrink()],
);
ScaffoldMessenger.of(context)
..hideCurrentMaterialBanner()
..showMaterialBanner(materialBanner);
},
),
],
),
),
);
}
}