Line data Source code
1 : import 'package:tech_proof/domain/entities/movie_entity.dart';
2 : import 'package:tech_proof/presentation/widgets/tt_loading_logo.dart';
3 : import 'package:cached_network_image/cached_network_image.dart';
4 : import 'package:flutter/material.dart';
5 : import 'package:go_router/go_router.dart';
6 :
7 : class TtMovieGrid extends StatelessWidget {
8 6 : const TtMovieGrid({
9 : super.key,
10 : required this.movieList,
11 : });
12 :
13 : final List<MovieEntity> movieList;
14 :
15 6 : @override
16 : Widget build(BuildContext context) {
17 6 : return SliverGrid(
18 : gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
19 : crossAxisCount: 2,
20 : crossAxisSpacing: 16,
21 : mainAxisSpacing: 16,
22 : childAspectRatio: 0.7,
23 : ),
24 6 : delegate: SliverChildBuilderDelegate(
25 12 : childCount: movieList.length,
26 6 : (context, index) {
27 :
28 6 : return GestureDetector(
29 0 : onTap: () {
30 0 : context.push('/movieDetail/${movieList[index].id}');
31 : },
32 6 : child: Card(
33 : elevation: 4,
34 6 : child: Column(
35 : crossAxisAlignment: .stretch,
36 6 : children: [
37 :
38 6 : Expanded(
39 6 : child: Stack(
40 6 : children: [
41 6 : Positioned.fill(
42 6 : child: Container(
43 : height: double.infinity,
44 6 : color: Colors.grey[400],
45 12 : child: Icon(Icons.movie, size: 64, color: Colors.grey[700]),
46 : ),
47 : ),
48 29 : if(movieList[index].posterPath != '' )Center(
49 5 : child: SizedBox(
50 : width: double.infinity,
51 :
52 5 : child: CachedNetworkImage(
53 20 : imageUrl: 'https://image.tmdb.org/t/p/w154${movieList[index].posterPath}',
54 : fit: BoxFit.cover,
55 20 : placeholder: (context, url) => Center(child: TtLoadingLogo( duration: Duration(milliseconds: 1500),),),
56 0 : errorWidget: (context, url, error) => Icon(Icons.error),
57 : ),
58 : ),
59 : ),
60 :
61 : ],
62 : ),
63 : ),
64 :
65 6 : Padding(
66 : padding: const EdgeInsets.all(8.0),
67 6 : child: Text(
68 18 : movieList[index].title,
69 6 : style: TextStyle(fontWeight: FontWeight.bold),
70 : maxLines: 1,
71 : overflow: TextOverflow.ellipsis,
72 : ),
73 : ),
74 : ],
75 : ),
76 : ),
77 : );
78 : },
79 : ),
80 : );
81 : }
82 : }
83 :
|