From bafec0df8e46e91bcaab32f0dbbcbe97a095ea42 Mon Sep 17 00:00:00 2001 From: mhakantekbas Date: Sun, 8 Jan 2023 18:12:25 +0300 Subject: [PATCH 1/3] home page editted --- lib/pages/BookDetailPage.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pages/BookDetailPage.dart b/lib/pages/BookDetailPage.dart index c189c0b..e183d4f 100644 --- a/lib/pages/BookDetailPage.dart +++ b/lib/pages/BookDetailPage.dart @@ -40,7 +40,7 @@ class _BookDetailPageState extends State { GestureDetector( onTap: () => Navigator.pop(context), child: Container( - padding: EdgeInsets.fromLTRB(20, 20, 0, 0), + padding: EdgeInsets.fromLTRB(20, 40, 0, 0), child: Icon(Icons.arrow_back_ios_new_outlined)), ), Container( From c32834d156dd79ce7873b7326315b54affb9eea7 Mon Sep 17 00:00:00 2001 From: mhakantekbas Date: Sun, 8 Jan 2023 18:16:49 +0300 Subject: [PATCH 2/3] home page editted --- lib/constants/constants.dart | 36 ++++++++ lib/main.dart | 5 +- lib/pages/BaseWidget.dart | 3 +- lib/pages/BookDetailPage.dart | 12 +-- lib/pages/BookListPage.dart | 128 ++++++++++++++++++---------- lib/pages/onBoarding.dart | 2 +- lib/services/book_api.dart | 18 ++++ lib/widgets/BookGridViewWidget.dart | 32 +++---- pubspec.lock | 7 ++ pubspec.yaml | 1 + 10 files changed, 169 insertions(+), 75 deletions(-) create mode 100644 lib/constants/constants.dart diff --git a/lib/constants/constants.dart b/lib/constants/constants.dart new file mode 100644 index 0000000..bfbd3ac --- /dev/null +++ b/lib/constants/constants.dart @@ -0,0 +1,36 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:google_fonts/google_fonts.dart'; + +class Constants { + Constants._(); + static const Color secondaryPrimaryColor = Color.fromARGB(255, 53, 83, 88); + + static const Color secondaryColor = Color.fromARGB(255, 255, 205, 55); + + static const Color primaryColor = Color.fromRGBO(53, 83, 88, 1); + +// Fonts + static TextStyle kTextStyleHeading = TextStyle( + fontFamily: GoogleFonts.ubuntu().toString(), + fontSize: 16.0, + overflow: TextOverflow.ellipsis, + color: Colors.grey); + + static TextStyle kTextStyleSubheading = TextStyle( + fontFamily: GoogleFonts.ubuntu().toString(), + fontSize: 14.0, + overflow: TextOverflow.ellipsis, + ); + + static TextStyle kTextStyleBookTitle = GoogleFonts.ubuntu(fontSize: 25); + + static TextStyle kTextStyleBookCategory = GoogleFonts.ubuntu(fontSize: 20); + + static TextStyle kTextStyleMenuHeader = + GoogleFonts.ubuntu(fontSize: 15, fontWeight: FontWeight.bold); + + static const TextStyle kTextStyleBody = TextStyle( + fontSize: 16.0, + ); +} diff --git a/lib/main.dart b/lib/main.dart index 1f1886b..d241b91 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import 'package:term_project/constants/constants.dart'; import 'package:term_project/pages/BaseWidget.dart'; import 'package:term_project/pages/BookDetailPage.dart'; import 'package:term_project/pages/BookListPage.dart'; @@ -38,10 +39,10 @@ class MyApp extends StatelessWidget { title: 'Book List', theme: ThemeData( colorScheme: ColorScheme.fromSwatch() - .copyWith(primary: const Color.fromRGBO(53, 83, 88, 1))), + .copyWith(primary: Constants.secondaryPrimaryColor)), routes: { '/': (context) => const HasData(), - BookListScreen.routeName: (context) => BookPage(), + BookPage.routeName: (context) => BookPage(), SettingsPage.routeName: (context) => SettingsPage(), SignInPage.routeName: (context) => SignInPage(), OnBoarding.routeName: (context) => const OnBoarding(), diff --git a/lib/pages/BaseWidget.dart b/lib/pages/BaseWidget.dart index 86038eb..2e437d8 100644 --- a/lib/pages/BaseWidget.dart +++ b/lib/pages/BaseWidget.dart @@ -1,5 +1,6 @@ import 'package:curved_navigation_bar/curved_navigation_bar.dart'; import 'package:flutter/material.dart'; +import 'package:term_project/constants/constants.dart'; import 'package:term_project/pages/search_page.dart'; import 'BookListPage.dart'; @@ -36,7 +37,7 @@ class _BottomBarState extends State { }); }, animationDuration: const Duration(milliseconds: 350), - color: const Color.fromRGBO(53, 83, 88, 1), + color: Constants.primaryColor, backgroundColor: Colors.white, items: const [ Icon( diff --git a/lib/pages/BookDetailPage.dart b/lib/pages/BookDetailPage.dart index e183d4f..39abdc9 100644 --- a/lib/pages/BookDetailPage.dart +++ b/lib/pages/BookDetailPage.dart @@ -37,12 +37,12 @@ class _BookDetailPageState extends State { body: SingleChildScrollView( child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ - GestureDetector( - onTap: () => Navigator.pop(context), - child: Container( - padding: EdgeInsets.fromLTRB(20, 40, 0, 0), - child: Icon(Icons.arrow_back_ios_new_outlined)), - ), + Container( + padding: EdgeInsets.fromLTRB(20, 40, 0, 0), + child: IconButton( + icon: Icon(Icons.arrow_back_ios), + onPressed: () => Navigator.pop(context), + )), Container( decoration: BoxDecoration(), height: MediaQuery.of(context).size.width / 1.3, diff --git a/lib/pages/BookListPage.dart b/lib/pages/BookListPage.dart index 2247a7f..315e7db 100644 --- a/lib/pages/BookListPage.dart +++ b/lib/pages/BookListPage.dart @@ -14,20 +14,8 @@ import '../Provider/TodoProvider.dart'; import '../widgets/BookGridViewWidget.dart'; import '../widgets/search.dart'; -class BookListScreen extends StatelessWidget { - static const routeName = '/bookList-page'; - @override - Widget build(BuildContext context) { - return MaterialApp( - title: "BOOKS", - debugShowCheckedModeBanner: false, - theme: ThemeData(primarySwatch: Colors.grey), - home: BookPage(), - ); - } -} - class BookPage extends StatefulWidget { + static const routeName = '/bookList-page'; BookPage({super.key}); @override @@ -37,14 +25,30 @@ class BookPage extends StatefulWidget { class _BookPageState extends State { FirebaseServices _firebaseServices = FirebaseServices(); late Future> bookListFuture; + late ScrollController scrollController; + late ScrollController scrollController2; @override void initState() { // TODO: implement initState super.initState(); + scrollController = ScrollController(); + scrollController2 = ScrollController(); bookListFuture = BookApi.getBookData(); } + int current = 0; + List items = [ + 'Fantasy', + 'Philosophy', + 'Psychology', + 'Horror', + 'Dystopian', + 'Biography', + 'Science Fiction', + 'Mystery', + 'Thriller', + ]; @override Widget build(BuildContext context) { final provider = Provider.of(context); @@ -115,49 +119,79 @@ class _BookPageState extends State { height: 10, ), SizedBox( - height: 200, + height: MediaQuery.of(context).size.height / 3, child: BookGridViewWidget( + controller: scrollController, bookListFuture: bookListFuture, provider: provider, ), ), - Row( - children: [ - Container( - decoration: const BoxDecoration( - border: Border(bottom: BorderSide(color: Colors.blue))), - child: Text( - "Genres", - style: GoogleFonts.ubuntu( - fontSize: 15, fontWeight: FontWeight.bold), - ), - padding: const EdgeInsets.all(8), - ), - Container( - child: Text( - "Bestsellers", - style: GoogleFonts.ubuntu( - fontSize: 15, fontWeight: FontWeight.bold), - ), - padding: const EdgeInsets.all(8), - ), - Container( - child: Text( - "Newest", - style: GoogleFonts.ubuntu( - fontSize: 15, fontWeight: FontWeight.bold), - ), - padding: const EdgeInsets.all(8), - ), - ], + SizedBox( + width: double.infinity, + height: 60, + child: ListView.builder( + physics: const BouncingScrollPhysics(), + itemCount: items.length, + scrollDirection: Axis.horizontal, + itemBuilder: (ctx, index) { + return Column( + children: [ + GestureDetector( + onTap: () { + setState(() { + current = index; + }); + }, + child: AnimatedContainer( + duration: const Duration(milliseconds: 300), + margin: const EdgeInsets.all(5), + width: 80, + height: 45, + decoration: BoxDecoration( + color: current == index + ? Colors.white70 + : Colors.white54, + borderRadius: current == index + ? BorderRadius.circular(15) + : BorderRadius.circular(10), + border: current == index + ? Border.all( + color: Color.fromARGB(255, 53, 83, 88), + width: 2) + : null, + ), + child: Center( + child: Text( + items[index], + style: GoogleFonts.laila( + fontWeight: FontWeight.w500, + color: current == index + ? Colors.black + : Colors.grey), + ), + ), + ), + ), + Visibility( + visible: current == index, + child: Container( + width: 5, + height: 5, + decoration: const BoxDecoration( + color: Color.fromARGB(255, 53, 83, 88), + shape: BoxShape.circle), + )) + ], + ); + }), ), const SizedBox( height: 10, ), - Container( - child: BookGridViewWidget( - provider: provider, bookListFuture: bookListFuture), - ), + BookGridViewWidget( + controller: scrollController2, + provider: provider, + bookListFuture: BookApi.getDataBygenre(q: items[current])), ]), color: Colors.white, ), diff --git a/lib/pages/onBoarding.dart b/lib/pages/onBoarding.dart index 1d92706..1d67706 100644 --- a/lib/pages/onBoarding.dart +++ b/lib/pages/onBoarding.dart @@ -35,7 +35,7 @@ class _OnBoardingState extends State { child: Container( padding: const EdgeInsets.all(10), child: const Text( - "Pick 3 Genres to Get Started!", + "Pick 4 Genres to Get Started!", style: TextStyle(fontSize: 30, color: Colors.white), ), ), diff --git a/lib/services/book_api.dart b/lib/services/book_api.dart index 6dc23dd..be03245 100644 --- a/lib/services/book_api.dart +++ b/lib/services/book_api.dart @@ -40,4 +40,22 @@ class BookApi { } return books; } + + static Future> getDataBygenre({String q = "computer"}) async { + List books = []; + var url = 'https://www.googleapis.com/books/v1/volumes?q=subject:$q'; + final uri = Uri.parse(url); + final response = await http.get(uri); + final body = response.body; + final json = jsonDecode(body); + final results = json['items'] as List; + print('api started'); + + if (books is List) { + books = results.map((e) => BookModel.fromMap(e)).toList(); + } else { + return []; + } + return books; + } } diff --git a/lib/widgets/BookGridViewWidget.dart b/lib/widgets/BookGridViewWidget.dart index bced2b0..3252df4 100644 --- a/lib/widgets/BookGridViewWidget.dart +++ b/lib/widgets/BookGridViewWidget.dart @@ -2,18 +2,20 @@ import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; +import 'package:term_project/constants/constants.dart'; import '../Provider/TodoProvider.dart'; import '../model/book_model.dart'; import '../pages/BookDetailPage.dart'; class BookGridViewWidget extends StatelessWidget { - const BookGridViewWidget({ - Key? key, - required this.provider, - required this.bookListFuture, - }) : super(key: key); - + const BookGridViewWidget( + {Key? key, + required this.provider, + required this.bookListFuture, + this.controller}) + : super(key: key); + final ScrollController? controller; final TodoProvider? provider; final Future> bookListFuture; @@ -24,12 +26,11 @@ class BookGridViewWidget extends StatelessWidget { if (snapshot.hasData) { List books = snapshot.data!; return GridView.builder( - physics: const NeverScrollableScrollPhysics(), + controller: controller, shrinkWrap: true, gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent( maxCrossAxisExtent: 200, - childAspectRatio: 1, - crossAxisSpacing: 1, + childAspectRatio: 1 / 1.2, mainAxisSpacing: 15), itemCount: books.length, itemBuilder: (BuildContext ctx, index) { @@ -87,15 +88,10 @@ class BookGridViewWidget extends StatelessWidget { const SizedBox( height: 5, ), - Text( - books[index].title!, - style: GoogleFonts.ubuntu(), - overflow: TextOverflow.ellipsis, - ), - Text( - books[index].author!, - style: GoogleFonts.ubuntu(color: Colors.grey), - ) + Text(books[index].title!, + style: Constants.kTextStyleHeading), + Text(books[index].author!, + style: Constants.kTextStyleSubheading) ], ); }); diff --git a/pubspec.lock b/pubspec.lock index 1e92bfd..2375909 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -244,6 +244,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "5.0.0" + flutter_screenutil: + dependency: "direct main" + description: + name: flutter_screenutil + url: "https://pub.dartlang.org" + source: hosted + version: "5.6.0" flutter_test: dependency: "direct dev" description: flutter diff --git a/pubspec.yaml b/pubspec.yaml index 4457f3e..6deaddb 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -50,6 +50,7 @@ dependencies: email_validator: ^2.1.17 cached_network_image: ^3.2.3 provider: ^6.0.5 + flutter_screenutil: ^5.6.0 dev_dependencies: flutter_test: From 29fcba8899b0e198d01834e1f177234f339edda5 Mon Sep 17 00:00:00 2001 From: mhakantekbas Date: Mon, 9 Jan 2023 20:48:52 +0300 Subject: [PATCH 3/3] search scroll fixed --- lib/widgets/search.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/widgets/search.dart b/lib/widgets/search.dart index f0f782e..7307ac5 100644 --- a/lib/widgets/search.dart +++ b/lib/widgets/search.dart @@ -6,9 +6,8 @@ import 'package:term_project/Provider/TodoProvider.dart'; import 'package:term_project/services/book_api.dart'; import 'package:term_project/widgets/BookGridViewWidget.dart'; -import '../model/book_model.dart'; - class SearchBook extends SearchDelegate { + ScrollController controller = ScrollController(); @override List? buildActions(BuildContext context) { return [ @@ -44,6 +43,7 @@ class SearchBook extends SearchDelegate { child: BookGridViewWidget( provider: todoProvider, bookListFuture: BookApi.getDataByQuery(q: query), + controller: controller, )); }