Line data Source code
1 : import 'package:tech_proof/data/repositories/movies_repository_imp.dart';
2 : import 'package:tech_proof/presentation/widgets/tt_app_bar.dart';
3 : import 'package:tech_proof/src/favorites/presentation/widgets/favorite_movie.dart';
4 : import 'package:tech_proof/src/movie_detail/presentation/bloc/movie_detail_bloc.dart';
5 : import 'package:cached_network_image/cached_network_image.dart';
6 : import 'package:flutter/material.dart';
7 : import 'package:flutter_bloc/flutter_bloc.dart';
8 :
9 : class MovieDetailPage extends StatelessWidget {
10 : static const String routeName = '/movieDetail';
11 :
12 : final int id;
13 0 : const MovieDetailPage({super.key, required this.id});
14 :
15 0 : @override
16 : Widget build(BuildContext context) {
17 0 : return BlocProvider(
18 0 : create: (context) => MovieDetailBloc(
19 0 : movieRepository: context.read<MovieRepositoryImpl>(),
20 0 : movieId: id,
21 0 : )..add(MovieDetailInit()),
22 :
23 0 : child: BlocBuilder<MovieDetailBloc, MovieDetailState>(
24 0 : builder: (context, state) {
25 0 : return MovieDetailsView();
26 : },
27 : ),
28 : );
29 : }
30 : }
31 :
32 : class MovieDetailsView extends StatelessWidget {
33 1 : const MovieDetailsView({super.key});
34 :
35 1 : @override
36 : Widget build(BuildContext context) {
37 2 : final state = context.watch<MovieDetailBloc>().state;
38 1 : final isLoaded = state is MovieDetailLoaded;
39 : if (isLoaded) {
40 2 : return Scaffold(appBar: TtAppBar(),
41 1 : body: Stack(
42 1 : children: [
43 1 : Positioned.fill(
44 4 : child: CachedNetworkImage(imageUrl: 'https://image.tmdb.org/t/p/w500${state.movieDetail.posterPath}', fit: .fitHeight,)
45 : ),
46 1 : Positioned.fill(
47 : top: 200,
48 :
49 1 : child: Container(
50 : color: Colors.black87,
51 :
52 1 : child: SingleChildScrollView(
53 1 : child: Padding(
54 1 : padding: .symmetric(horizontal: 16, vertical: 24),
55 1 : child: Column(
56 : mainAxisSize: .max,
57 : crossAxisAlignment: .start,
58 1 : children: [
59 1 : Wrap(
60 : spacing: 8.0,
61 : runSpacing: 4.0,
62 6 : children: state.movieDetail.genres.map((tag) => _buildTagChip(tag)).toList(),
63 : ),
64 4 : Text(state.movieDetail.title, style: TextStyle(fontSize: 44, fontWeight: FontWeight.bold, color: Colors.white), textAlign: .left,),
65 5 : Text('Release Date: ${state.movieDetail.releaseDate}', style: TextStyle(fontSize: 16, color: Colors.white), textAlign: .left,),
66 1 : SizedBox(height: 8,),
67 4 : Text(state.movieDetail.synopsis, style: TextStyle(fontSize: 16, color: Colors.white70), textAlign: .left,),
68 1 : SizedBox(height: 16,),
69 5 : Text('Rating: ${state.movieDetail.rating}/10', style: TextStyle(fontSize: 16, color: Colors.white), textAlign: .left,),
70 1 : SizedBox(height: 16,),
71 :
72 :
73 : ],
74 : ),
75 : ),
76 : ),
77 : ),
78 : ),
79 1 : Positioned(
80 : top: 175,
81 : right: 16,
82 1 : child: FavoriteMovie(
83 1 : movie: state.movieDetail,
84 : ),
85 : ),]
86 : ),);
87 : }
88 1 : return Container();
89 : }
90 :
91 : }
92 :
93 :
94 1 : Widget _buildTagChip(String tag) {
95 1 : return Chip(
96 1 : label: Text(tag),
97 1 : backgroundColor: Colors.blue.shade100,
98 2 : labelStyle: TextStyle(color: Colors.blue.shade800),
99 1 : padding: EdgeInsets.symmetric(horizontal: 8, vertical: 4),
100 : );
101 : }
|