Skip to content

SG MEDIA #3439

Description

@surahatagumaneh

imimportport 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'dart:async'; // Required for DateTime.now().subtract

/// DATA_MODEL
/// Represents a user profile within the social media application.
class User {
final String username;
final String profileImageUrl;
final String bio;
final int postCount;
final int followerCount;
final int followingCount;

User({
required this.username,
required this.profileImageUrl,
this.bio = '',
this.postCount = 0,
this.followerCount = 0,
this.followingCount = 0,
});
}

/// Represents a single post with associated user, media, and engagement metrics.
class Post {
final User user;
final String? imageUrl; // Nullable, as it might be a video
final bool isVideo; // New: indicates if this post is a video
final String? videoThumbnailUrl; // New: URL for video thumbnail
final String caption;
int likes; // Modifiable to reflect user interaction
int comments; // Modifiable
bool isLiked; // New: Tracks if the current user has liked this post
final DateTime timestamp;

Post({
required this.user,
this.imageUrl,
this.isVideo = false,
this.videoThumbnailUrl,
this.caption = '',
this.likes = 0,
this.comments = 0,
this.isLiked = false,
required this.timestamp,
}) : assert(
(imageUrl != null && !isVideo && videoThumbnailUrl == null) ||
(videoThumbnailUrl != null && isVideo && imageUrl == null),
'A post must contain either an imageUrl (if not a video) or a videoThumbnailUrl (if a video).');
}

/// Manages the data for the main feed, including a list of posts.
/// Notifies listeners when the data changes (e.g., when a post is liked).
class FeedData extends ChangeNotifier {
final List _posts;

List get posts => _posts;

FeedData() : _posts = _generateDummyPosts();

/// Generates a static list of dummy posts for demonstration.
static List _generateDummyPosts() {
// Note: The profileImageUrl here should ideally match the one used in AuthData
// for the 'bespoke_ui_dev' user if they log in. For simplicity, it's hardcoded
// here to ensure the dummy posts display correctly.
final User currentUser = User(
username: 'bespoke_ui_dev',
profileImageUrl: 'https://www.gstatic.com/flutter-onestack-prototype/genui/example_1.jpg',
bio: 'Flutter enthusiast | UI/UX Designer',
postCount: 15,
followerCount: 1234,
followingCount: 567,
);

final User user1 = User(
  username: 'travel_junkie',
  profileImageUrl: 'https://www.gstatic.com/flutter-onestack-prototype/genui/example_1.jpg',
);
final User user2 = User(
  username: 'foodie_explorer',
  profileImageUrl: 'https://www.gstatic.com/flutter-onestack-prototype/genui/example_1.jpg',
);
final User user3 = User(
  username: 'coding_daily',
  profileImageUrl: 'https://www.gstatic.com/flutter-onestack-prototype/genui/example_1.jpg',
);

return <Post>[
  Post(
    user: user1,
    imageUrl: 'https://www.gstatic.com/flutter-onestack-prototype/genui/example_1.jpg',
    caption: 'Beautiful sunset views from the mountain top! ⛰️🌅 #travel #nature',
    likes: 1250,
    comments: 35,
    isLiked: false,
    timestamp: DateTime.now().subtract(const Duration(hours: 2)),
  ),
  Post(
    user: user2,
    imageUrl: 'https://www.gstatic.com/flutter-onestack-prototype/genui/example_1.jpg',
    caption: 'Delicious homemade pasta! So proud of this dish. 🍝 #foodie #cooking',
    likes: 890,

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions