-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create ui top rated
- Loading branch information
Showing
11 changed files
with
349 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
), | ||
), | ||
), | ||
); | ||
}, | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'), | ||
), | ||
); | ||
}, | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.