subscribeToTopic method

  1. @override
Future<bool> subscribeToTopic(
  1. String topic
)
override

Subscribes to a topic by persisting it in localStorage and shows a notification.

Implementation

@override
Future<bool> subscribeToTopic(String topic) async {
  try {
    final topics = await getSubscribedTopics();
    if (!topics.contains(topic)) {
      topics.add(topic);
      _saveTopics(topics);
    }
    _showBrowserConfirmation(
      'Subscribed',
      'You are now subscribed to topic: $topic',
    );
    return true;
  } catch (e) {
    return false;
  }
}