Skip to content

Commit

Permalink
trending screen
Browse files Browse the repository at this point in the history
  • Loading branch information
mo7amedaliEbaid committed Nov 12, 2023
1 parent ef9f4eb commit 704fad6
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 33 deletions.
3 changes: 3 additions & 0 deletions lib/app/app_strings.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
sealed class AppStrings {
static const String appName = "CimaCima";
static const String home = "Home";
static const String bookmarks = "Bookmarks";
static const String nowShowing = "Now Showing";
static const String popular = "Popular";
static const String upcoming = "Upcoming";
static const String trending = "Trending";
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ final upcomingMoviesStateNotifier =
AutoDisposeStateNotifierProvider<MovieNotifier, MovieState>(
(ref) => MovieNotifier());

final trendingMoviesStateNotifier =
AutoDisposeStateNotifierProvider<MovieNotifier, MovieState>(
(ref) => MovieNotifier());

final genreStateNotifier =
AutoDisposeStateNotifierProvider<GenreNotifier, GenreState>(
(ref) => GenreNotifier()..getGenres());
3 changes: 3 additions & 0 deletions lib/features/movies/presentation/screens/movies.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:movies_riverpod/features/bookmarks/presentation/screens/bookmark_screen.dart';
import 'package:movies_riverpod/features/movies/presentation/screens/home_screen.dart';
import 'package:movies_riverpod/features/movies/presentation/screens/trending_screen.dart';
import 'package:movies_riverpod/features/movies/presentation/screens/upcoming_screen.dart';
import 'package:movies_riverpod/shared/responsive/responsive.dart';
import 'package:movies_riverpod/shared/widgets/app_bar.dart';
Expand Down Expand Up @@ -46,6 +47,8 @@ class _MoviesState extends State<Movies> {
case 1:
return const UpcomingScreen();
case 2:
return const TrendingScreen();
case 3:
return const BookmarkScreen();
default:
return Container();
Expand Down
61 changes: 61 additions & 0 deletions lib/features/movies/presentation/screens/trending_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:movies_riverpod/app/app_dimensions.dart';
import 'package:movies_riverpod/app/app_strings.dart';
import 'package:movies_riverpod/features/movies/presentation/providers/movies_state_notifier_provider.dart';
import 'package:movies_riverpod/features/movies/presentation/widgets/custom_screen_title.dart';
import 'package:movies_riverpod/features/movies/presentation/widgets/trending_movies.dart';

import 'package:movies_riverpod/features/movies/presentation/widgets/upcomig_movies.dart';
import 'package:movies_riverpod/shared/network/network_values.dart';

class TrendingScreen extends ConsumerStatefulWidget {
const TrendingScreen({super.key});

@override
ConsumerState<ConsumerStatefulWidget> createState() => _TrendingScreenState();
}

class _TrendingScreenState extends ConsumerState<TrendingScreen> {
@override
void initState() {
super.initState();
Future(() {
ref
.read(trendingMoviesStateNotifier.notifier)
.getMovies(type: EndPoints.trending);
});
trendingControl.addListener(trendingScrollListener);
}

@override
void dispose() {
super.dispose();
trendingControl.removeListener(trendingScrollListener);
}

ScrollController trendingControl = ScrollController();

void trendingScrollListener() {
if (trendingControl.position.maxScrollExtent == trendingControl.offset) {
ref
.read(trendingMoviesStateNotifier.notifier)
.getMovies(type: EndPoints.trending);
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(controller: trendingControl, slivers: const [
SliverToBoxAdapter(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [CustomScreenTtle(screentitle: AppStrings.trending)],
),
),
const TrendingMovies()
]),
);
}
}
30 changes: 4 additions & 26 deletions lib/features/movies/presentation/screens/upcoming_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:movies_riverpod/app/app_dimensions.dart';
import 'package:movies_riverpod/app/app_strings.dart';
import 'package:movies_riverpod/features/movies/presentation/providers/movies_state_notifier_provider.dart';
import 'package:movies_riverpod/features/movies/presentation/widgets/custom_screen_title.dart';
import 'package:movies_riverpod/features/movies/presentation/widgets/now_showing_movies.dart';
import 'package:movies_riverpod/features/movies/presentation/widgets/popular_movies.dart';
import 'package:movies_riverpod/features/movies/presentation/widgets/upcomig_movies.dart';
Expand All @@ -21,62 +22,39 @@ class _UpcomingScreenState extends ConsumerState<UpcomingScreen> {
void initState() {
super.initState();
Future(() {
// ref.read(nowShowingMoviesStateNotifier.notifier).getMovies(type: EndPoints.nowShowing);
ref
.read(upcomingMoviesStateNotifier.notifier)
.getMovies(type: EndPoints.upcoming);
});
// nowShowingControl.addListener(nowShowingScrollListener);
upcomingControl.addListener(upcomingScrollListener);
}

@override
void dispose() {
super.dispose();
// nowShowingControl.removeListener(nowShowingScrollListener);
upcomingControl.removeListener(upcomingScrollListener);
}

// ScrollController nowShowingControl = ScrollController();
ScrollController upcomingControl = ScrollController();

/* void nowShowingScrollListener() {
if (nowShowingControl.position.maxScrollExtent ==
nowShowingControl.offset) {
ref.read(nowShowingMoviesStateNotifier.notifier).getMovies(type: EndPoints.nowShowing);
}
}*/

void upcomingScrollListener() {
if (upcomingControl.position.maxScrollExtent == upcomingControl.offset) {
ref
.read(upcomingMoviesStateNotifier.notifier)
.getMovies(type: EndPoints.popular);
.getMovies(type: EndPoints.upcoming);
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(controller: upcomingControl, slivers: [
body: CustomScrollView(controller: upcomingControl, slivers: const [
SliverToBoxAdapter(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: EdgeInsets.only(
left: AppDimensions.p18,
bottom: AppDimensions.p24,
),
child: Text(
AppStrings.upcoming,
style: Theme.of(context).textTheme.titleMedium,
),
),
],
children: [CustomScreenTtle(screentitle: AppStrings.upcoming)],
),
),

const UpcomingMovies()
]),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import 'package:movies_riverpod/shared/widgets/rating_bar.dart';
import '../../../../models/movie/movie.dart';
import '../providers/state/genre_state.dart';

class UpcomingMovie extends ConsumerWidget {
class CustomMovieCard extends ConsumerWidget {
final Movie movie;

const UpcomingMovie({Key? key, required this.movie}) : super(key: key);
const CustomMovieCard({Key? key, required this.movie}) : super(key: key);

@override
Widget build(BuildContext context, WidgetRef ref) {
Expand Down
23 changes: 23 additions & 0 deletions lib/features/movies/presentation/widgets/custom_screen_title.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:flutter/material.dart';

import '../../../../app/app_dimensions.dart';

class CustomScreenTtle extends StatelessWidget {
const CustomScreenTtle({super.key, required this.screentitle});

final String screentitle;

@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.only(
left: AppDimensions.p18,
bottom: AppDimensions.p24,
),
child: Text(
screentitle,
style: Theme.of(context).textTheme.titleMedium,
),
);
}
}
36 changes: 36 additions & 0 deletions lib/features/movies/presentation/widgets/trending_movies.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:movies_riverpod/features/movies/presentation/providers/movies_state_notifier_provider.dart';

import 'package:movies_riverpod/features/movies/presentation/widgets/popular_card.dart';
import 'package:movies_riverpod/features/movies/presentation/widgets/shimmer/movies_vertical_shimmer.dart';
import 'package:movies_riverpod/features/movies/presentation/widgets/custom_movie_card.dart';
import 'package:movies_riverpod/routes/app_router.dart';
import 'package:go_router/go_router.dart';

class TrendingMovies extends ConsumerWidget {
const TrendingMovies({super.key});


@override
Widget build(BuildContext context, WidgetRef ref) {
final trendingMoviesState = ref.watch(trendingMoviesStateNotifier);
return trendingMoviesState.hasData
? SliverList(
delegate: SliverChildBuilderDelegate((context, index) {
if (index < trendingMoviesState.movies.length) {
final movie = trendingMoviesState.movies[index];
return GestureDetector(
onTap: () {
context.pushNamed(Routes.movieDetail.name,
extra: movie.id);
},
child: CustomMovieCard(movie: movie));
}
else {
return const Center(child: CircularProgressIndicator());
}
}, childCount: trendingMoviesState.movies.length + 1))
: const SliverFillRemaining(hasScrollBody: true,child: MoviesVerticalListShimmer());
}
}
4 changes: 2 additions & 2 deletions lib/features/movies/presentation/widgets/upcomig_movies.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:movies_riverpod/features/movies/presentation/providers/movies_st

import 'package:movies_riverpod/features/movies/presentation/widgets/popular_card.dart';
import 'package:movies_riverpod/features/movies/presentation/widgets/shimmer/movies_vertical_shimmer.dart';
import 'package:movies_riverpod/features/movies/presentation/widgets/upcoming_card.dart';
import 'package:movies_riverpod/features/movies/presentation/widgets/custom_movie_card.dart';
import 'package:movies_riverpod/routes/app_router.dart';
import 'package:go_router/go_router.dart';

Expand All @@ -25,7 +25,7 @@ class UpcomingMovies extends ConsumerWidget {
context.pushNamed(Routes.movieDetail.name,
extra: movie.id);
},
child: UpcomingMovie(movie: movie));
child: CustomMovieCard(movie: movie));
}
else {
return const Center(child: CircularProgressIndicator());
Expand Down
14 changes: 11 additions & 3 deletions lib/shared/widgets/app_bottom_navigation.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:flutter/material.dart';
import 'package:movies_riverpod/app/app_text_styles.dart';

import '../../app/app_strings.dart';

class AppBottomNavigation extends StatelessWidget {
final int currentIndex;

Expand All @@ -13,15 +15,21 @@ class AppBottomNavigation extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BottomNavigationBar(
type: BottomNavigationBarType.fixed,
onTap: (index) => onTapped(index),
currentIndex: currentIndex,
selectedLabelStyle:
AppTextStyles.bodyMedium.copyWith(fontWeight: FontWeight.bold),
unselectedLabelStyle: AppTextStyles.bodySmall,
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(icon: Icon(Icons.movie), label: 'Home'),
BottomNavigationBarItem(icon: Icon(Icons.upcoming), label: 'Upcoming'),
BottomNavigationBarItem(icon: Icon(Icons.bookmark), label: 'Bookmarks')
BottomNavigationBarItem(
icon: Icon(Icons.movie), label: AppStrings.home),
BottomNavigationBarItem(
icon: Icon(Icons.upcoming), label: AppStrings.upcoming),
BottomNavigationBarItem(
icon: Icon(Icons.trending_up), label: AppStrings.trending),
BottomNavigationBarItem(
icon: Icon(Icons.bookmark), label: AppStrings.bookmarks)
],
);
}
Expand Down
Binary file added screenshots/portrait/trending.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/portrait/trendingdark.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 704fad6

Please sign in to comment.