'How to implement the functionality of adding to favorites?

I need to implement the functionality of adding news to favorites, so that when you click on the icon, the news is added to favorites and displayed on a separate page "Favorites". In the project I use GetX. Please tell me how can I do this? Below is the news code that comes from the API. I will be grateful for help)

class Source {
  String id;
  String name;

  Source({required this.id, required this.name});

  factory Source.fromJson(Map<String, dynamic> json) {
    return Source(id: json['id'], name: json['name']);
  }
}

import 'source_model.dart';

class Article {
  Source source;
  String author;
  String title;
  String description;
  String url;
  String urlToImage;
  String publishedAt;
  String content;

  Article(
      {required this.source,
      required this.author,
      required this.title,
      required this.description,
      required this.url,
      required this.urlToImage,
      required this.publishedAt,
      required this.content});


  factory Article.fromJson(Map<String, dynamic> json) {
    return Article(
      source: Source.fromJson(json['source']),
      author: json['author'] ?? "",
      title: json['title'] ?? "",
      description: json['description'] ?? "",
      url: json['url'] ?? "",
      urlToImage: json['urlToImage'] ?? "",
      publishedAt: json['publishedAt'] ?? "",
      content: json['content'] ?? "",
    );
  }
}


Solution 1:[1]

To store articles, you'll require a document database. There are multiple options available and all of them depend on your requirements.

If you want to store the favourites only locally, then Hive is a great dart document database that you can use.

If you want the favourites accessible everywhere, then you'll have to store them in a remote database. In that case you can use Firestore or create a custom backend functionality for that.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Advait