Skip to content

Commit

Permalink
view books on details view page
Browse files Browse the repository at this point in the history
  • Loading branch information
He9sham committed May 4, 2024
1 parent becf02b commit 3a407f0
Show file tree
Hide file tree
Showing 14 changed files with 198 additions and 52 deletions.
12 changes: 11 additions & 1 deletion lib/core/utils/app_routers.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import 'package:bookly_app/core/Services/server_locator.dart';
import 'package:bookly_app/features/Search/presantation/view/search_view.dart';
import 'package:bookly_app/features/home/data/Models/bookmodels/bookmodels.dart';
import 'package:bookly_app/features/home/data/repo/home_repo_impl.dart';
import 'package:bookly_app/features/home/presantation/view_models/similer_books/similar_books_cubit.dart';
import 'package:bookly_app/features/home/presantation/views/book_details_view.dart';
import 'package:bookly_app/features/navigation_bar_control.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';

abstract class AppRouter {
Expand All @@ -20,7 +25,12 @@ abstract class AppRouter {
),
GoRoute(
path: '/Bookview',
builder: (context, state) => const BookDetailsView(),
builder: (context, state) => BlocProvider(
create: (context) => SimilarBooksCubit(
getIt.get<HomeRepoImpl>(),
),
child: BookDetailsView(bookmodels: state.extra as Bookmodels,),
),
),
GoRoute(
path: '/SearchView',
Expand Down
5 changes: 3 additions & 2 deletions lib/core/widgets/buttom_action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ class CustomButtom extends StatelessWidget {
required this.textcolor,
required this.text,
required this.backgroundColor,
this.borderRadius,
this.borderRadius, this.onPressed,
});
final Color textcolor;
final String text;
final Color backgroundColor;
final BorderRadius? borderRadius;
final void Function()? onPressed;
@override
Widget build(BuildContext context) {
return SizedBox(
Expand All @@ -25,7 +26,7 @@ class CustomButtom extends StatelessWidget {
borderRadius: borderRadius!,
),
),
onPressed: () {},
onPressed: onPressed ,
child: Text(
text,
style: Styles.textmid.copyWith(
Expand Down
1 change: 1 addition & 0 deletions lib/features/home/data/repo/home_repo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ import 'package:dartz/dartz.dart';
abstract class HomeRepo {
Future<Either<Failure, List<Bookmodels>>> fetchNewsetBooks();
Future<Either<Failure, List<Bookmodels>>> fetchFeatureBooks();
Future<Either<Failure, List<Bookmodels>>> fetchSimilarBooks({required String category});
}
22 changes: 21 additions & 1 deletion lib/features/home/data/repo/home_repo_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class HomeRepoImpl implements HomeRepo {
try {
var data = await apiService.get(
endpoints:
'volumes?Filtering=free-ebooks&Sorting=newest&q=subject:sports');
'volumes?Filtering=free-ebooks&Sorting=newest&q=subject:computer science');
List<Bookmodels> books = [];
for (var item in data['items']) {
try {
Expand All @@ -48,4 +48,24 @@ class HomeRepoImpl implements HomeRepo {
return left(ServerFailure(e.toString()));
}
}

@override
Future<Either<Failure, List<Bookmodels>>> fetchSimilarBooks(
{required String category}) async {
try {
var data = await apiService.get(
endpoints:
'volumes?Filtering=free-ebooks&Sorting=relevance&q=subject:programming');
List<Bookmodels> books = [];
for (var item in data['items']) {
books.add(Bookmodels.fromJson(item));
}
return right(books);
} catch (e) {
if (e is DioException) {
return left(ServerFailure.fromDioerro(e));
}
return left(ServerFailure(e.toString()));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:bloc/bloc.dart';
import 'package:bookly_app/features/home/data/Models/bookmodels/bookmodels.dart';
import 'package:bookly_app/features/home/data/repo/home_repo.dart';
import 'package:equatable/equatable.dart';

part 'similar_books_state.dart';

class SimilarBooksCubit extends Cubit<SimilarBooksState> {
SimilarBooksCubit(this.homeRepo) : super(SimilarBooksInitial());

final HomeRepo homeRepo;

Future<void> fetchSimilerBooks({required String category}) async {
emit(SimilarBooksLoading());
var result = await homeRepo.fetchSimilarBooks(category: category);

result.fold((failure) {
emit(SimilarBooksFailuer(failure.errmessage));
}, (books) {
emit(SimilarBooksSuccess(books));
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
part of 'similar_books_cubit.dart';

sealed class SimilarBooksState extends Equatable {
const SimilarBooksState();

@override
List<Object> get props => [];
}

final class SimilarBooksInitial extends SimilarBooksState {}

final class SimilarBooksLoading extends SimilarBooksState {}

final class SimilarBooksSuccess extends SimilarBooksState {
final List<Bookmodels> books;

const SimilarBooksSuccess(this.books);
}

final class SimilarBooksFailuer extends SimilarBooksState {
final String errmessage;

const SimilarBooksFailuer(this.errmessage);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import 'package:bookly_app/features/home/presantation/views/widgets/books_similer_list_view.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
Expand All @@ -6,7 +7,7 @@ import '../../../../../core/utils/styles.dart';

class SimilatorBooksSection extends StatelessWidget {
const SimilatorBooksSection({super.key});

@override
Widget build(BuildContext context) {
return Column(
Expand All @@ -23,7 +24,7 @@ class SimilatorBooksSection extends StatelessWidget {
const SizedBox(
height: 15,
),
const SimiletorBooKsView()
const SimiletorBooKsView()
],
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import 'package:bookly_app/core/utils/styles.dart';
import 'package:bookly_app/features/home/data/Models/bookmodels/bookmodels.dart';
import 'package:bookly_app/features/home/presantation/views/widgets/book_Action_View.dart';
import 'package:bookly_app/features/home/presantation/views/widgets/custom_list_view_item.dart';
import 'package:bookly_app/features/home/presantation/views/widgets/rating_book_view_detaisl.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';

class BookDetailsSection extends StatelessWidget {
const BookDetailsSection({super.key});
const BookDetailsSection({super.key, required this.bookmodels});
final Bookmodels bookmodels;
@override
Widget build(BuildContext context) {
var width = MediaQuery.of(context).size.width;
Expand All @@ -15,23 +17,24 @@ class BookDetailsSection extends StatelessWidget {
children: [
Padding(
padding: EdgeInsets.symmetric(horizontal: width * 0.17, vertical: 35),
child: const CustomBookImage(
imageurl: 'https://www.google.com/imgres?q=image%20book&imgurl=https%3A%2F%2Fjuliaquinn.com%2FWP%2Fwp-content%2Fuploads%2F2024%2F02%2FJQ_special-edition-covers.png&imgrefurl=https%3A%2F%2Fjuliaquinn.com%2Fseries%2Fbridgertons%2F&docid=ic5YTf7bLucAvM&tbnid=oyEHFjA5A9yW0M&vet=12ahUKEwjovbWVuOSFAxWfcaQEHRI8De8QM3oECDoQAA..i&w=439&h=600&hcb=2&ved=2ahUKEwjovbWVuOSFAxWfcaQEHRI8De8QM3oECDoQAA',
child: CustomBookImage(
imageurl: bookmodels.volumeInfo.imageLinks.thumbnail,
),
),
SizedBox(
height: height * 0.01,
),
Text(
'The Jungle Book',
textAlign: TextAlign.center,
bookmodels.volumeInfo.title!,
style: Styles.textmlarg
.copyWith(fontFamily: GoogleFonts.spectral().fontFamily),
),
const SizedBox(
height: 4,
),
Text(
'Rudyard Kipling',
bookmodels.volumeInfo.authors![0],
style: Styles.textmid.copyWith(
fontFamily: GoogleFonts.montserrat().fontFamily,
color: Colors.white.withOpacity(0.6),
Expand All @@ -40,11 +43,16 @@ class BookDetailsSection extends StatelessWidget {
const SizedBox(
height: 14,
),
const BookRate(),
BookRate(
languch: bookmodels.volumeInfo.language!,
pagecount: bookmodels.volumeInfo.pageCount!,
),
const SizedBox(
height: 37,
),
const BooksAction(),
BooksAction(
bookmodels: bookmodels,
),
],
);
}
Expand Down
26 changes: 22 additions & 4 deletions lib/features/home/presantation/views/book_details_view.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
import 'package:bookly_app/features/home/data/Models/bookmodels/bookmodels.dart';
import 'package:bookly_app/features/home/presantation/view_models/similer_books/similar_books_cubit.dart';
import 'package:bookly_app/features/home/presantation/views/widgets/book_details_view_body.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

class BookDetailsView extends StatelessWidget {
const BookDetailsView({super.key});
class BookDetailsView extends StatefulWidget {
const BookDetailsView({super.key, required this.bookmodels});
final Bookmodels bookmodels;
@override
State<BookDetailsView> createState() => _BookDetailsViewState();
}

class _BookDetailsViewState extends State<BookDetailsView> {
@override
void initState() {
BlocProvider.of<SimilarBooksCubit>(context).fetchSimilerBooks(
category: widget.bookmodels.volumeInfo.categories![0],
);
super.initState();
}

@override
Widget build(BuildContext context) {
return const Scaffold(
body: BookDetailsViewBody(),
return Scaffold(
body: BookDetailsViewBody(
bookmodels: widget.bookmodels,
),
);
}
}
18 changes: 11 additions & 7 deletions lib/features/home/presantation/views/widgets/book_Action_View.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import 'package:bookly_app/core/widgets/buttom_action.dart';
import 'package:bookly_app/features/home/data/Models/bookmodels/bookmodels.dart';
import 'package:flutter/material.dart';

class BooksAction extends StatelessWidget {
const BooksAction({super.key});

const BooksAction({super.key, required this.bookmodels});
final Bookmodels bookmodels;
@override
Widget build(BuildContext context) {
return const Row(
return Row(
children: [
Expanded(
const Expanded(
child: CustomButtom(
text: '19.99€',
text: 'Free',
textcolor: Colors.black,
backgroundColor: Colors.white,
borderRadius: BorderRadius.only(
Expand All @@ -21,10 +22,13 @@ class BooksAction extends StatelessWidget {
),
Expanded(
child: CustomButtom(
onPressed: () {
bookmodels.volumeInfo.previewLink;
},
text: 'Free preview',
textcolor: Colors.white,
backgroundColor: Color(0xffEF8262),
borderRadius: BorderRadius.only(
backgroundColor: const Color(0xffEF8262),
borderRadius: const BorderRadius.only(
topRight: Radius.circular(12),
bottomRight: Radius.circular(12),
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
import 'package:bookly_app/features/home/data/Models/bookmodels/bookmodels.dart';
import 'package:bookly_app/features/home/presantation/views/Sections/Similator_books_section.dart';
import 'package:bookly_app/features/home/presantation/views/Sections/book_details_section.dart';
import 'package:bookly_app/features/home/presantation/views/widgets/customappbar_bookview.dart';

import 'package:flutter/material.dart';

class BookDetailsViewBody extends StatelessWidget {
const BookDetailsViewBody({super.key});

const BookDetailsViewBody({super.key, required this.bookmodels});
final Bookmodels bookmodels;
@override
Widget build(BuildContext context) {
return const CustomScrollView(
return CustomScrollView(
slivers: [
SliverFillRemaining(
hasScrollBody: false,
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 30.7, vertical: 40.2),
padding: const EdgeInsets.symmetric(horizontal: 30.7, vertical: 40.2),
child: Column(
children: [
CustomappBar(),
BookDetailsSection(),
Expanded(
const CustomappBar(),
BookDetailsSection(
bookmodels: bookmodels,
),
const Expanded(
child: SizedBox(
height: 50,
),
),
SimilatorBooksSection(),
const SimilatorBooksSection(),
],
),
),
Expand Down
Loading

0 comments on commit 3a407f0

Please sign in to comment.