0

I am going to develop a video streaming app like Netflix using flutter and Appwrite. I want to add a featured movie image inside home screen like bellow image. featured image

I have saved this image in appwritre storage bucket and save image url inside movies_details collection in featuredImage_url attribute.

enter image description here

this is my Movies model class

class MoviesModel {
  final String name;
  final String description;
  final String durationInMinutes;
  final String thumbnailUrl;
  final String genres;
  final String tags;
  final String releasedDate;
  final String cast;
  final String videoUrl;
   final String featuredImageUrl;
   final String isFeaturedImageUrl;
  
 
 
  MoviesModel( {
    required this.name,
    required this.description,
    required this.durationInMinutes,
    required this.thumbnailUrl,
    required this.genres,
    required this.tags,
    required this.releasedDate,
    required this.cast,
    required this.videoUrl,
    required this.featuredImageUrl,
     required this.isFeaturedImageUrl,
   
  });

  Map<String, dynamic> toMap() {
    return <String, dynamic>{
     
      'name': name,
      'description': description,
      'durationInMinutes': durationInMinutes,
      'thumbnailUrl': thumbnailUrl,
      'genres': genres,
      'tags': tags,
      'releasedDate': releasedDate,
      'cast': cast,
      'videoUrl': videoUrl,
      'featuredImageUrl':featuredImageUrl,
      'isFeaturedImageUrl':isFeaturedImageUrl,
     
    };
  }

  factory MoviesModel.fromMap(Document doc) {
    final id = doc.$id;
    final map = doc.data;
    return MoviesModel(
      name: map['name'] as String,
      description: map['description'] as String,
      durationInMinutes: map['durationInMinutes'] as String,
      thumbnailUrl: map['thumbnailUrl'] as String,
      genres: map['genres'] as String,
      tags: map['tags'] as String,
      releasedDate: map['releasedDate'] as String,
      cast: map['cast'] as String,
      videoUrl: map['videoUrl'] as String, 
      featuredImageUrl: map['featuredImageUrl'] as String, 
      isFeaturedImageUrl: map['isFeaturedImageUrl'] as String,  
    
    );
  }
}

This is my repo_code


  Future getFeaturedtMovie()async{
    final respose = await database.listDocuments(
            databaseId: databaseId,
            collectionId: collectionId,
            queries: [
              
                Query.equal('isFeaturedImageUrl', 'Yes'),
            ]
        );
        
        final data = respose.documents;
       

This is my home screen code

FutureBuilder<List<MoviesModel>>(
                      future: _MoviesRepo.getFeaturedtMovie(),
                      builder: (BuildContext context,
                          AsyncSnapshot<List<MoviesModel>> snapshot) {
                        if (!snapshot.hasData) {
                          return Center(child: Text('Loading...'));
                        } else if (snapshot.hasError) {
                          print('Error');
                        }
                        return snapshot.data!.isEmpty
                            ? Center(child: Text('No Featured Movie in List.'))
                            : ListView(
                                children: snapshot.data!.map((movies) {
                                  return Container(
                                    margin: EdgeInsets.only(right: 5),                               
                                    child: Image.network(movies.featuredImageUrl),
                                  );
                                }).toList(),
                              );
                      },
                    ),

Please give me a solution.Thank You

sameera
  • 23
  • 5

0 Answers0