showStatsNotification method

Future<void> showStatsNotification({
  1. required BuildContext context,
  2. required NetLensStats stats,
})

Shows current stats notification. It formats stats into simple notification which is displayed when stats has changed.

Implementation

Future<void> showStatsNotification({
  required BuildContext context,
  required NetLensStats stats,
}) async {
  try {
    if (_isNotificationProcessing) {
      return;
    }
    final message = _getNotificationMessage(context: context, stats: stats);
    if (message == _notificationMessageDisplayed) {
      return;
    }

    _isNotificationProcessing = true;

    await _flutterLocalNotificationsPlugin?.show(
      id: 0,
      title: context
          .i18n(NetLensTranslationKey.notificationTotalRequests)
          .replaceAll(_callCount, stats.total.toString()),
      body: message,
      notificationDetails: _notificationDetails,
      payload: _payload,
    );

    _notificationMessageDisplayed = message;
  } catch (error) {
    NetLensUtils.log(error.toString());
  } finally {
    _isNotificationProcessing = false;
  }
}