Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 5 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,9 @@
# Task 3 - Book Store App
## Task 3 - Book Store App

Task resolution process:
<img src="https://user-images.githubusercontent.com/81244287/188034079-aabbe56a-12ec-4b35-bddd-e8175c0d05d5.png" align="left" height="640" width="360" >

- Fork the repo
- Clone the forked repo to your local machine
- Resolve the task
- Commit your solution
- Push to GitHub
- create a pull request
<img src="https://user-images.githubusercontent.com/81244287/188034083-3a58a88f-3ce1-4c27-88ae-c88dbd952f29.png" align="left" height="640" width="360" >

<img src="https://user-images.githubusercontent.com/81244287/188034088-49470b76-a098-4e87-864f-14957ae79402.png" align="left" height="640" width="360" >


### Task 3:
Build a book store mobile application. The store contain a list of available books with the ability to add custom books to the store as well as view, order them.

* Don't use pre-made widgets (packges).
* It's ok to use icons packages.
* Use Getx for state management.

## UI
### Main Page
The main page should contain a list of the available books. When tapping on a book, the second page (Book Details Page) will be navigated. Use Scrollable view for the list of books. ALso there is a simple search on the top of the page.


### Cart Page (Optional)
This page can view the ordered books.

### Details Page
This have the details of the book which is:
- Book name
- Author
- Desciption
- Image
- Rate (constant)

### Add Page
It is the page where you can add new books to the store.

## FLow
1. Build the UI (from figma design).
2. seperate the widgets to small and organized files.
3. Build models that contain the book data (You can build one model or more).
4. Try to seperate the logic (Functions and data) from the UI.

## Figma Design
https://www.figma.com/file/4BGkiFfTPT7b8K9pyFTBD6/Online-Book-Store-App-(2019)-(Community)?node-id=0%3A1
<img src="https://user-images.githubusercontent.com/81244287/188034096-fa4671a6-85d3-4e63-925a-9d771de2ca43.png" align="left" height="640" width="360" >
93 changes: 93 additions & 0 deletions assets/fonts/Poppins/OFL.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Copyright 2020 The Poppins Project Authors (https://github.com/itfoundry/Poppins)

This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL


-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------

PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.

The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.

DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).

"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.

"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.

PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.

5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.

TERMINATION
This license becomes null and void if any of the above conditions are
not met.

DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
Binary file added assets/fonts/Poppins/Poppins-Black.ttf
Binary file not shown.
Binary file added assets/fonts/Poppins/Poppins-BlackItalic.ttf
Binary file not shown.
Binary file added assets/fonts/Poppins/Poppins-Bold.ttf
Binary file not shown.
Binary file added assets/fonts/Poppins/Poppins-BoldItalic.ttf
Binary file not shown.
Binary file added assets/fonts/Poppins/Poppins-ExtraBold.ttf
Binary file not shown.
Binary file added assets/fonts/Poppins/Poppins-ExtraBoldItalic.ttf
Binary file not shown.
Binary file added assets/fonts/Poppins/Poppins-ExtraLight.ttf
Binary file not shown.
Binary file not shown.
Binary file added assets/fonts/Poppins/Poppins-Italic.ttf
Binary file not shown.
Binary file added assets/fonts/Poppins/Poppins-Light.ttf
Binary file not shown.
Binary file added assets/fonts/Poppins/Poppins-LightItalic.ttf
Binary file not shown.
Binary file added assets/fonts/Poppins/Poppins-Medium.ttf
Binary file not shown.
Binary file added assets/fonts/Poppins/Poppins-MediumItalic.ttf
Binary file not shown.
Binary file added assets/fonts/Poppins/Poppins-Regular.ttf
Binary file not shown.
Binary file added assets/fonts/Poppins/Poppins-SemiBold.ttf
Binary file not shown.
Binary file added assets/fonts/Poppins/Poppins-SemiBoldItalic.ttf
Binary file not shown.
Binary file added assets/fonts/Poppins/Poppins-Thin.ttf
Binary file not shown.
Binary file added assets/fonts/Poppins/Poppins-ThinItalic.ttf
Binary file not shown.
Binary file added assets/images/book_1.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 assets/images/book_2.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 assets/images/book_3.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 assets/images/book_4.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 assets/images/person.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions assets/images/preview_icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/images/reviews_icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/images/search.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
100 changes: 100 additions & 0 deletions lib/controllers/book_controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../models/book.dart';
import '../models/data.dart';
import '../style.dart';
import '../views/screens/cart_page.dart';
import '../views/screens/home_page.dart';

class BookController extends GetxController {
RxString searchResult = ('').obs;
String currentPage = 'home page';

void successfulBookPurchase(BuildContext context) => Get.snackbar(
'Successful the book purchase',
'Go to cart page to view your purchases',
icon: const Icon(CupertinoIcons.shopping_cart),
onTap: (GetSnackBar snackBar) {
Get.closeAllSnackbars();
Get.to(const CartPage());
},
);

void addBookSnackBar(BuildContext context, bool isSuccessfulAdd) => Get.snackbar(
isSuccessfulAdd ? 'The book has been successfully added' : 'Failed to add book',
isSuccessfulAdd ? 'Go to the home page to view the book added' : 'You have entered invalid data, please fill in the fields with valid data',
icon: const Icon(CupertinoIcons.add),
onTap: (GetSnackBar snackBar) {
if (isSuccessfulAdd) {
Get.closeAllSnackbars();
Get.to(const HomePage());
}
},
);

String get getHeaderText => searchResult.isNotEmpty ? 'Result' : 'Book List';
Color get getSVGSearchColor => searchResult.isNotEmpty ? blue : hintTextColor;

bool isBookStoreEmpty() => Data.books.isEmpty;
bool isNotFoundBooks() => filterBooks(searchResult.value).isEmpty;
bool isPurchasedBooksEmpty() => Data.purchasedBooks.isEmpty;
bool isFieldsEmpty(Map<String, String> map) {
bool isInvaild = false;
for(String value in map.values){
if(value.contains(',')) isInvaild = true;
}
return map.containsValue('') || isInvaild;
}

void buyBook(Book book) => Data.purchasedBooks.add(book);
double getCorrectRating(double rating) {
String rate = rating.toString();
return double.parse(rate.substring(rate.length - 1, rate.length)) < 5
? double.parse(rate.substring(0, 1))
: double.parse('${rate.substring(0, 1)}.5');
}

void addBook(Map<String, String> newBook) {
double rating = getCorrectRating(double.parse(newBook['rating'].toString()));
Data.books.add(Book(
name: newBook['name'].toString(),
author: newBook['author'].toString(),
image: newBook['image'].toString(),
description: newBook['description'].toString(),
price: double.parse(newBook['price'].toString()),
rating: rating > 5 ? 5 : rating,
));
}

Color iconcolorCurrentPage(String currentPage) {
return currentPage == this.currentPage ? black : unselectedIconColor;
}

List<Book> filterBooks(String nameBook) {
if (searchResult.isEmpty) return Data.books;
return Data.books
.where((e) => e.name.toLowerCase().contains(nameBook))
.toList();
}

List<Icon> getBookRating(double rating) {
List<Icon> icons = [];

for (int i = 0; i < 5; i++) {
icons.add(
Icon(
(rating-- >= 1.0)
? (Icons.star)
: (rating == 0.5 || rating == -0.5
? Icons.star_half
: Icons.star),
color: rating + 1 > 0 ? (iconsColor) : halfIconColor,
size: 14,
),
);
}
return icons;
}
}
23 changes: 17 additions & 6 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';

import 'controllers/book_controller.dart';
import 'views/screens/home_page.dart';

void main() {
SystemChrome.setSystemUIOverlayStyle(
const SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarIconBrightness: Brightness.dark,
),
);

runApp(const MyApp());
}

Expand All @@ -9,12 +21,11 @@ class MyApp extends StatelessWidget {

@override
Widget build(BuildContext context) {
return const MaterialApp(
home: Scaffold(
body: Center(
child: Text("Book Store App"),
),
),
Get.put(BookController());
return const GetMaterialApp(
title: 'Book Store',
debugShowCheckedModeBanner: false,
home: HomePage(),
);
}
}
14 changes: 14 additions & 0 deletions lib/models/book.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Book {
String name, author, image, description;
double price, rating;

Book({
required this.name,
required this.author,
required this.image,
required this.description,
required this.price,
required this.rating,
});

}
42 changes: 42 additions & 0 deletions lib/models/data.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'package:get/get.dart';

import 'book.dart';

class Data{
static RxList<Book> books = <Book>[
Book(
name: 'Life A COMPILATION OF SHORT STORIES AND POETRY',
author: 'ZOE DAVIS',
image: 'assets/images/book_1.jpg',
description: 'Sit cillum aliqua in velit dolore nulla id ullamco occaecat exercitation quis laborum minim. Ea nulla occaecat do duis id et nulla aute officia enim tempor elit. Consequat ea ullamco sit proident sit sit do ea nulla veniam Lorem id. Irure in sint fugiat aliquip. Tempor qui aute quis tempor occaecat nulla id irure minim aute aute dolore esse. Sunt ut magna mollit do duis commodo incididunt ipsum duis enim enim.',
price: 65.99,
rating: 4.5,
),
Book(
name: 'ULTRALEARNING',
author: 'Scott H. Young',
image: 'assets/images/book_2.jpg',
description: 'Elit magna velit culpa exercitation occaecat duis in eu sit sunt. Ipsum mollit do irure id. Incididunt occaecat nisi veniam occaecat do eiusmod sit.',
price: 69.99,
rating: 5.0,
),
Book(
name: 'THE PROPHET',
author: 'Kahlil Gibran',
image: 'assets/images/book_3.jpg',
description: 'Duis consequat elit reprehenderit Lorem consequat in esse elit pariatur ut officia id sit sunt. Sit magna voluptate quis sunt ad adipisicing irure labore pariatur Lorem do minim proident irure. Ad quis excepteur ut ea sint ullamco quis nulla proident voluptate laboris. Dolore cupidatat sint nisi sint enim aute amet officia aute.',
price: 44.99,
rating: 4.0,
),
Book(
name: 'THE POWER OF HABIT',
author: 'Charles Duhigg',
image: 'assets/images/book_4.jpg',
description: 'Et ea dolore proident officia ea elit ea sunt ut ullamco consectetur incididunt. Lorem dolor Lorem nostrud Lorem. In esse deserunt sunt dolore sit dolore est reprehenderit nostrud et. Eu enim ea mollit anim. Veniam aute sunt sunt est commodo fugiat ullamco labore mollit est.',
price: 89.99,
rating: 4.5,
),
].obs;

static RxList<Book> purchasedBooks = <Book>[].obs;
}
Loading