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
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"cmake.configureOnOpen": true,
"editor.stickyScroll.enabled": true
}
49 changes: 49 additions & 0 deletions lib/add_book_page/add_book_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import 'package:my_book_store_app/add_book_page/add_book_page_views/Add_book_button.dart';
import 'package:my_book_store_app/add_book_page/add_book_page_views/reusable_text_button.dart';
import 'package:my_book_store_app/book_details_page/book_details_views/top_bar.dart';
import 'package:my_book_store_app/main.dart';
import 'package:flutter/material.dart';

class AddBookPage extends StatelessWidget {
const AddBookPage({Key? key}) : super(key: key);
static TextEditingController bookName = TextEditingController();
static TextEditingController authorName = TextEditingController();
static TextEditingController price = TextEditingController();
static TextEditingController imageLink = TextEditingController();
static TextEditingController rating = TextEditingController();
static TextEditingController description = TextEditingController();

@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () => FocusManager.instance.primaryFocus?.unfocus(),
child: Scaffold(
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const TopBar(),
Padding(
padding: const EdgeInsets.only(left: 27),
child: title('Add Book')),
Expanded(
child: ListView(
padding: const EdgeInsets.only(left: 20, top: 30, right: 20),
children: [
reusableTextField( hintText: 'Book Name..', lines: 1, myControler: bookName),
reusableTextField( hintText: 'Author Name..', lines: 1, myControler: authorName),
reusableTextField( hintText: 'Price in \$..', lines: 1, myControler: price),
reusableTextField( hintText: 'Image Link..', lines: 1, myControler: imageLink),
reusableTextField( hintText: 'Rating..', lines: 1, myControler: rating),
Container(
height: 172,
margin: EdgeInsets.only( bottom: MediaQuery.of(context).viewInsets.bottom + 150),
child: reusableTextField( hintText: 'Description', lines: 6, myControler: description)),
],
),
)
],
),
floatingActionButton: const AddBookButton()),
);
}
}
65 changes: 65 additions & 0 deletions lib/add_book_page/add_book_page_views/Add_book_button.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import 'package:my_book_store_app/add_book_page/add_book_page.dart';
import 'package:my_book_store_app/main.dart';
import 'package:my_book_store_app/models/book_model.dart';
import 'package:flutter/material.dart';

class AddBookButton extends StatelessWidget {
const AddBookButton({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Padding(
padding: const EdgeInsets.only(bottom: 20, left: 25, right: 5),
child: Container(
width: 350,
height: 70,
decoration: BoxDecoration(
color: Colors.black,
borderRadius: BorderRadius.circular(13),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.1),
spreadRadius: 1,
blurRadius: 4,
offset: const Offset(0, 9))
]),
child: TextButton(
style: TextButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
)),
child: const Text("Add",
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.w400,
color: Colors.white)),
onPressed: () {
BookModel.book.add(BookModel(
imageUrl: AddBookPage.imageLink.text,
rating: (double.parse(AddBookPage.rating.text)),
title: AddBookPage.bookName.text,
author: AddBookPage.authorName.text,
price: AddBookPage.price.text,
description: AddBookPage.description.text,
inCart: false));
Navigator.push(context,
MaterialPageRoute(builder: (context) => const MyHomePage()));
AddBookPage.imageLink.clear();
AddBookPage.rating.clear();
AddBookPage.bookName.clear();
AddBookPage.authorName.clear();
AddBookPage.price.clear();
AddBookPage.description.clear();
}),
),
),
],
),
);
}
}
32 changes: 32 additions & 0 deletions lib/add_book_page/add_book_page_views/reusable_text_button.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:flutter/material.dart';

Widget reusableTextField({required hintText, required int lines, required TextEditingController myControler}) {
return Container(
margin: const EdgeInsets.only(top: 17),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(15),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.1),
spreadRadius: 2,
blurRadius: 6,
offset: const Offset(0, 6))
]),
child: TextField(
maxLines: 6,
minLines: lines,
textInputAction: TextInputAction.newline,
decoration: InputDecoration(
hintText: hintText,
hintStyle: const TextStyle(color: Colors.grey),
border: OutlineInputBorder(borderRadius: BorderRadius.circular(15)),
enabledBorder: const OutlineInputBorder(borderSide: BorderSide.none),
focusedBorder: OutlineInputBorder(
borderSide: const BorderSide(width: 1, color: Colors.blue),
borderRadius: BorderRadius.circular(15))),
autofocus: false,
controller: myControler,
),
);
}
37 changes: 37 additions & 0 deletions lib/book_details_page/book_details_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'package:my_book_store_app/book_details_page/book_details_views/book_author.dart';
import 'package:my_book_store_app/book_details_page/book_details_views/book_cover.dart';
import 'package:my_book_store_app/book_details_page/book_details_views/book_description.dart';
import 'package:my_book_store_app/book_details_page/book_details_views/book_rating.dart';
import 'package:my_book_store_app/book_details_page/book_details_views/book_title.dart';
import 'package:my_book_store_app/book_details_page/book_details_views/bottom_buttons.dart';
import 'package:my_book_store_app/book_details_page/book_details_views/top_bar.dart';
import 'package:my_book_store_app/models/book_model.dart';
import 'package:flutter/material.dart';

class BookDetailsPage extends StatelessWidget {
const BookDetailsPage({Key? key, required this.desiredBook,required this.desiredBookIndex})
: super(key: key);
final BookModel desiredBook;
final int desiredBookIndex;

@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
const TopBar(),
Column(
children: [
BookCover(url: desiredBook.imageUrl),
BookTitle(title: desiredBook.title),
BookAuthor(author: desiredBook.author),
const SizedBox(height: 5),
BookRating(rating: desiredBook.rating),
BookDescription(description: desiredBook.description),
],
)
],
),
floatingActionButton: BuyAndDetailsButtons(boughtBook: desiredBook, desiredBookIndex: desiredBookIndex));
}
}
16 changes: 16 additions & 0 deletions lib/book_details_page/book_details_views/book_author.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:flutter/material.dart';

class BookAuthor extends StatelessWidget {
const BookAuthor({Key? key, required this.author}) : super(key: key);
final String author;
@override
Widget build(BuildContext context) {
return Text(author,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
height: 1,
color: Colors.grey,
));
}
}
19 changes: 19 additions & 0 deletions lib/book_details_page/book_details_views/book_cover.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'package:flutter/material.dart';

class BookCover extends StatelessWidget {
const BookCover({Key? key, required this.url}) : super(key: key);
final String url;
@override
Widget build(BuildContext context) {
return Container(
height: 300,
width: 220,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(url),
alignment: Alignment.topCenter,
fit: BoxFit.cover),
borderRadius: BorderRadius.circular(7)),
);
}
}
19 changes: 19 additions & 0 deletions lib/book_details_page/book_details_views/book_description.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'package:flutter/material.dart';
class BookDescription extends StatelessWidget {
const BookDescription({Key? key, required this.description}) : super(key: key);
final String description;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(left: 10, right: 10, top: 2),
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
padding: const EdgeInsets.only(bottom: 100),
child: SizedBox(
width: 400,
height: 100,
child: Text(description, style: TextStyle(fontSize: 15, color: Colors.grey[700], height: 1.4))),
),
);
}
}
27 changes: 27 additions & 0 deletions lib/book_details_page/book_details_views/book_rating.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:flutter/material.dart';

class BookRating extends StatelessWidget {
const BookRating({Key? key, required this.rating}) : super(key: key);
final double rating;
@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [StarDisplay(value: rating), Text(" $rating/5")],
);
}
}

class StarDisplay extends StatelessWidget {
final double value;
const StarDisplay({Key? key, this.value = 0}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
mainAxisSize: MainAxisSize.min,
children: List.generate(5, (index) {
return Icon(index < value.round() ? Icons.star : Icons.star_border, color: Colors.amber);
}),
);
}
}
10 changes: 10 additions & 0 deletions lib/book_details_page/book_details_views/book_title.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:flutter/material.dart';

class BookTitle extends StatelessWidget {
const BookTitle({Key? key, required this.title}) : super(key: key);
final String title;
@override
Widget build(BuildContext context) {
return Text(title, style: const TextStyle( fontSize: 30, fontWeight: FontWeight.bold, height: 2));
}
}
109 changes: 109 additions & 0 deletions lib/book_details_page/book_details_views/bottom_buttons.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import 'package:my_book_store_app/cart_page/cart_page.dart';
import 'package:my_book_store_app/models/book_model.dart';
import 'package:flutter/material.dart';

class BuyAndDetailsButtons extends StatelessWidget {
const BuyAndDetailsButtons(
{Key? key, required this.boughtBook, required this.desiredBookIndex})
: super(key: key);
final BookModel boughtBook;
final int desiredBookIndex;

@override
Widget build(BuildContext context) {
String price = BookModel.book[desiredBookIndex].price;
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Padding(
padding: const EdgeInsets.only(bottom: 20, left: 25),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Spacer(flex: 2),
Container(
width: 150,
height: 45,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(13),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.1),
spreadRadius: 1,
blurRadius: 4,
offset: const Offset(0, 9))
]),
child: TextButton(
style: TextButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
)),
child: const Icon(Icons.preview, color: Colors.black54),
onPressed: () => print('object'),
),
),
const Spacer(flex: 1),
Container(
width: 150,
height: 45,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(13),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.1),
spreadRadius: 1,
blurRadius: 4,
offset: const Offset(0, 9))
]),
child: TextButton(
style: TextButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
)),
child: const Icon(Icons.reviews, color: Colors.black54),
onPressed: () => print('object'),
),
),
const Spacer(flex: 2)
],
),
),
Padding(
padding: const EdgeInsets.only(right: 5),
child: Container(
width: 350,
height: 70,
decoration: BoxDecoration(
color: Colors.black,
borderRadius: BorderRadius.circular(13),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.1),
spreadRadius: 1,
blurRadius: 4,
offset: const Offset(0, 9))
]),
child: TextButton(
style: TextButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
)),
child: Text("Buy now for $price\$",
style: const TextStyle(fontSize: 17,fontWeight: FontWeight.w400, color: Colors.white)),
onPressed: () {
BookModel.book[desiredBookIndex].inCart = true;
Future.delayed(Duration(milliseconds: 150), () {Navigator.push(context,MaterialPageRoute(builder: (context) => const CartPage()));
});
},
),
),
),
],
),
);
}
}
Loading