Line data Source code
1 : import 'package:tech_proof/presentation/widgets/tt_app_bar.dart'; 2 : import 'package:tech_proof/presentation/widgets/tt_movie_grid.dart' show TtMovieGrid; 3 : import 'package:tech_proof/src/favorites/presentation/bloc/favorites_bloc.dart'; 4 : import 'package:flutter/material.dart'; 5 : import 'package:flutter_bloc/flutter_bloc.dart'; 6 : 7 : class FavoritesPage extends StatelessWidget { 8 1 : const FavoritesPage({super.key}); 9 : 10 1 : @override 11 : Widget build(BuildContext context) { 12 1 : return BlocBuilder<FavoritesBloc, FavoritesState>( 13 1 : builder: (context, state) { 14 1 : return FavoritesPageView(); 15 : }, 16 : ); 17 : } 18 : } 19 : 20 : class FavoritesPageView extends StatelessWidget { 21 1 : const FavoritesPageView({super.key}); 22 : 23 1 : @override 24 : Widget build(BuildContext context) { 25 2 : final currentState = context.watch<FavoritesBloc>().state; 26 : 27 1 : if (currentState is FavoritesLoaded) { 28 : 29 1 : return Scaffold( 30 1 : appBar: TtAppBar( 31 : title: 'Favorite Movies', 32 : ), 33 1 : body: CustomScrollView( 34 1 : slivers: [ 35 1 : SliverPadding( 36 1 : padding: EdgeInsets.all(24.0), 37 2 : sliver: TtMovieGrid(movieList: currentState.favoriteMovies), 38 : ), 39 2 : if (currentState.favoriteMovies.isEmpty) 40 1 : SliverToBoxAdapter( 41 1 : child: Padding( 42 : padding: const EdgeInsets.only(top: 24.0), 43 1 : child: Center( 44 1 : child: Text( 45 : 'No favorite movies yet. Start adding some!', 46 1 : style: TextStyle( 47 : fontSize: 18, 48 : fontWeight: FontWeight.bold, 49 : color: Colors.white, 50 : ), 51 : textAlign: TextAlign.center, 52 : ), 53 : ), 54 : ), 55 : ), 56 : ], 57 : ), 58 : ); 59 : } 60 1 : if (currentState is FavoritesError) { 61 1 : return Scaffold( 62 1 : appBar: TtAppBar(), 63 1 : body: Center( 64 1 : child: Text('An error occurred. Please try again later.'), 65 : ), 66 : ); 67 : } 68 1 : return SizedBox.shrink(); 69 : } 70 : } 71 :