CkSnackBar function

void CkSnackBar(
  1. String text, {
  2. required CkSnackBarType type,
  3. Duration? customDuration,
})

Implementation

void CkSnackBar(
  String text, {
  required CkSnackBarType type,
  Duration? customDuration,
}) {
  final overlayState = coreKitInstance.navigatorKey.currentState?.overlay;
  if (overlayState == null) return;

  final calculatedMs = 2000 + (text.length * 25);
  final displayDuration =
      customDuration ?? Duration(milliseconds: calculatedMs);

  _currentSnackBarEntry?.remove();
  _currentSnackBarEntry = null;

  late final OverlayEntry entry;

  entry = OverlayEntry(
    builder: (_) => _SnackBarOverlay(
      text: text,
      type: type,
      duration: displayDuration,
      onDismiss: () {
        entry.remove();
        if (_currentSnackBarEntry == entry) {
          _currentSnackBarEntry = null;
        }
      },
    ),
  );

  _currentSnackBarEntry = entry;
  overlayState.insert(entry);
}