Skip to content

Commit

Permalink
implement service top rated
Browse files Browse the repository at this point in the history
create ui top rated
  • Loading branch information
Goggxi committed Nov 19, 2022
1 parent 53549fd commit b1ec152
Show file tree
Hide file tree
Showing 11 changed files with 349 additions and 129 deletions.
4 changes: 4 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:provider/provider.dart';
import 'package:yt_flutter_movie_db/app_constants.dart';
import 'package:yt_flutter_movie_db/movie/pages/movie_page.dart';
import 'package:yt_flutter_movie_db/movie/providers/movie_get_discover_provider.dart';
import 'package:yt_flutter_movie_db/movie/providers/movie_get_top_rated_provider.dart';
import 'package:yt_flutter_movie_db/movie/repostories/movie_repository.dart';
import 'package:yt_flutter_movie_db/movie/repostories/movie_repository_impl.dart';

Expand Down Expand Up @@ -36,6 +37,9 @@ class App extends StatelessWidget {
ChangeNotifierProvider(
create: (_) => MovieGetDiscoverProvider(movieRepository),
),
ChangeNotifierProvider(
create: (_) => MovieGetTopRatedProvider(movieRepository),
),
],
child: MaterialApp(
title: 'Movie DB',
Expand Down
86 changes: 86 additions & 0 deletions lib/movie/components/movie_discover_component.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:yt_flutter_movie_db/movie/providers/movie_get_discover_provider.dart';
import 'package:yt_flutter_movie_db/widget/item_movie_widget.dart';

class MovieDiscoverComponent extends StatefulWidget {
const MovieDiscoverComponent({super.key});

@override
State<MovieDiscoverComponent> createState() => _MovieDiscoverComponentState();
}

class _MovieDiscoverComponentState extends State<MovieDiscoverComponent> {
@override
void initState() {
WidgetsBinding.instance.addPostFrameCallback((_) {
context.read<MovieGetDiscoverProvider>().getDicover(context);
});
super.initState();
}

@override
Widget build(BuildContext context) {
return SliverToBoxAdapter(
child: Consumer<MovieGetDiscoverProvider>(
builder: (_, provider, __) {
if (provider.isLoading) {
return Container(
margin: const EdgeInsets.symmetric(horizontal: 16.0),
height: 300.0,
width: double.infinity,
decoration: BoxDecoration(
color: Colors.black26,
borderRadius: BorderRadius.circular(12),
),
);
}

if (provider.movies.isNotEmpty) {
return CarouselSlider.builder(
itemCount: provider.movies.length,
itemBuilder: (_, index, __) {
final movie = provider.movies[index];
return ItemMovieWidget(
movie: movie,
heightBackdrop: 300,
widthBackdrop: double.infinity,
heightPoster: 160,
widthPoster: 100,
);
},
options: CarouselOptions(
height: 300.0,
viewportFraction: 0.8,
reverse: false,
autoPlay: true,
autoPlayCurve: Curves.fastOutSlowIn,
enlargeCenterPage: true,
scrollDirection: Axis.horizontal,
),
);
}

return Container(
margin: const EdgeInsets.symmetric(horizontal: 16.0),
height: 300.0,
width: double.infinity,
decoration: BoxDecoration(
color: Colors.black26,
borderRadius: BorderRadius.circular(12),
),
child: const Center(
child: Text(
'Not found discover movies',
style: TextStyle(
color: Colors.black45,
),
),
),
);
},
),
);
}
}
72 changes: 72 additions & 0 deletions lib/movie/components/movie_top_rated_component.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:yt_flutter_movie_db/movie/providers/movie_get_top_rated_provider.dart';
import 'package:yt_flutter_movie_db/widget/image_widget.dart';

class MovieTopRatedComponent extends StatefulWidget {
const MovieTopRatedComponent({super.key});

@override
State<MovieTopRatedComponent> createState() => _MovieTopRatedComponentState();
}

class _MovieTopRatedComponentState extends State<MovieTopRatedComponent> {
@override
void initState() {
WidgetsBinding.instance.addPostFrameCallback((_) {
context.read<MovieGetTopRatedProvider>().getTopRated(context);
});
super.initState();
}

@override
Widget build(BuildContext context) {
return SliverToBoxAdapter(
child: SizedBox(
height: 200,
child: Consumer<MovieGetTopRatedProvider>(
builder: (_, provider, __) {
if (provider.isLoading) {
return Container(
margin: const EdgeInsets.symmetric(horizontal: 16.0),
decoration: BoxDecoration(
color: Colors.black26,
borderRadius: BorderRadius.circular(12.0)),
);
}

if (provider.movies.isNotEmpty) {
return ListView.separated(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
scrollDirection: Axis.horizontal,
itemBuilder: (_, index) {
return ImageNetworkWidget(
imageSrc: provider.movies[index].posterPath,
height: 200,
width: 120,
radius: 12.0,
);
},
separatorBuilder: (_, __) => const SizedBox(
width: 8.0,
),
itemCount: provider.movies.length,
);
}

return Container(
margin: const EdgeInsets.symmetric(horizontal: 16.0),
decoration: BoxDecoration(
color: Colors.black26,
borderRadius: BorderRadius.circular(12.0),
),
child: const Center(
child: Text('Not found top rated movies'),
),
);
},
),
),
);
}
}
9 changes: 0 additions & 9 deletions lib/movie/models/movie_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,26 @@ class MovieModel {
MovieModel({
this.backdropPath,
required this.id,
required this.originalTitle,
required this.overview,
required this.popularity,
this.posterPath,
required this.releaseDate,
required this.title,
required this.voteAverage,
required this.voteCount,
});

final String? backdropPath;
final int id;
final String originalTitle;
final String overview;
final double popularity;
final String? posterPath;
final DateTime releaseDate;
final String title;
final double voteAverage;
final int voteCount;

factory MovieModel.fromMap(Map<String, dynamic> json) => MovieModel(
backdropPath: json["backdrop_path"] ?? '',
id: json["id"],
originalTitle: json["original_title"],
overview: json["overview"],
popularity: json["popularity"].toDouble(),
posterPath: json["poster_path"] ?? '',
releaseDate: DateTime.parse(json["release_date"]),
title: json["title"],
voteAverage: json["vote_average"].toDouble(),
voteCount: json["vote_count"],
Expand Down
Loading

0 comments on commit b1ec152

Please sign in to comment.