showMessage method
void
showMessage(
- BuildContext context, {
- required Message inputMessage,
- Duration duration = const Duration(seconds: 5),
showMessage get a context and a message and show it. note: tow message with same key not allowed.
Implementation
void showMessage(BuildContext context,
{required Message inputMessage,
Duration duration = const Duration(seconds: 5)}) async {
/// if the _overlayEntry is already displayes, do nothing.
if (_overlayEntry == null) {
_insertOverlay(context);
}
/// Prevent to show a message with same key (for similar key error issues).
if (displayingMessages.where((m) => m.key == inputMessage.key).isNotEmpty) {
return;
}
/// Prevent to show more than [maxMessages] messages.
if (_messages.length >= maxMessages) {
removeMessage(_messages.firstWhere((m) => !m.pinned,
orElse: () => _messages.first));
}
_messages.add(inputMessage);
notifyListeners();
}