Skip to content

Commit

Permalink
Removed anonymous login
Browse files Browse the repository at this point in the history
Added basic widget to add products (unimplemneted)
Added vendors list
Redesigned form widgets
  • Loading branch information
mohammadkamal committed Apr 25, 2021
1 parent 1fb2fd5 commit 1670c25
Show file tree
Hide file tree
Showing 21 changed files with 484 additions and 183 deletions.
16 changes: 13 additions & 3 deletions lib/Cart/ShoppingCartItem.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import 'package:Bayya/Cart/ShoppingCart.dart';
import 'package:Bayya/Catalog/Catalog.dart';
import 'package:Bayya/ItemWidgets/ShortDescriptionText.dart';
import 'package:Bayya/Product/ProductView.dart';
import 'package:Bayya/User/VendorsList.dart';
import 'package:Bayya/WidgetUtils/ShortDescriptionText.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:flutter/material.dart';
Expand All @@ -18,6 +19,8 @@ class ShoppingCartItem extends StatefulWidget {

class _ShoppingCartItemState extends State<ShoppingCartItem> {
String _imgURL = "";
String _vendor = 'Vendor not provided';

Future<void> _getImageURL() async {
var result = await FirebaseStorage.instance
.ref()
Expand Down Expand Up @@ -77,16 +80,23 @@ class _ShoppingCartItemState extends State<ShoppingCartItem> {
}

Widget _vendorText() {
_getVendorName();
return Container(
padding: const EdgeInsets.only(bottom: 4),
child: Text(
Provider.of<Catalog>(context).productsCatalog[widget.productId].vendor,
_vendor,
textAlign: TextAlign.left,
softWrap: true,
),
);
}

Future<void> _getVendorName() async {
var _result = await Provider.of<VendorsList>(context).getVendorNameByUid(
Provider.of<Catalog>(context).productsCatalog[widget.productId].vendor);
_vendor = _result;
}

Widget _minusButton() {
return IconButton(
icon: Icon(Icons.remove_circle_outline),
Expand Down Expand Up @@ -174,7 +184,7 @@ class _ShoppingCartItemState extends State<ShoppingCartItem> {
border: Border.all(width: 1, color: Colors.white),
color: Colors.white),
child: Row(
children: [_leftColumn(), _rightColumn()],
children: [_leftColumn(), _rightColumn(),],
),
));
}
Expand Down
65 changes: 43 additions & 22 deletions lib/Cart/ShoppingCartList.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,55 @@ import 'package:Bayya/Cart/ShoppingCartItem.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class ShoppingCartList extends StatelessWidget {
class ShoppingCartList extends StatefulWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Shopping Cart'),
),
body: Container(
color: Colors.grey,
child: ListView(
padding: EdgeInsets.symmetric(vertical: 8.0),
children: Provider.of<ShoppingCart>(context)
.shoppingItemQuantites
.isNotEmpty
? Provider.of<ShoppingCart>(context)
.shoppingItemQuantites
.keys
.map((e) {
return ShoppingCartItem(productId: e);
}).toList()
: [])),
floatingActionButton: FloatingActionButton.extended(
_ShoppingCartListState createState() => _ShoppingCartListState();
}

class _ShoppingCartListState extends State<ShoppingCartList> {
bool _isCartempty = true;

Widget _listOfProducts() {
return ListView(
padding: EdgeInsets.symmetric(vertical: 8.0),
children:
Provider.of<ShoppingCart>(context).shoppingItemQuantites.isNotEmpty
? Provider.of<ShoppingCart>(context)
.shoppingItemQuantites
.keys
.map((e) {
return ShoppingCartItem(productId: e);
}).toList()
: []);
}

Widget _proceedButton() {
if (!_isCartempty) {
return FloatingActionButton.extended(
onPressed: null,
label: Text(
'Proceed to checkout',
style: TextStyle(fontSize: 20),
),
backgroundColor: Colors.lightGreen[500]),
backgroundColor: Colors.lightGreen[500]);
} else {
return null;
}
}

@override
Widget build(BuildContext context) {
if (Provider.of<ShoppingCart>(context).shoppingItemQuantites.isEmpty) {
_isCartempty = true;
} else {
_isCartempty = false;
}
return Scaffold(
appBar: AppBar(
title: Text('Shopping Cart'),
),
body: Container(color: Colors.grey, child: _listOfProducts()),
floatingActionButton: _proceedButton()
);
}
}
75 changes: 75 additions & 0 deletions lib/Catalog/AddProduct.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import 'package:flutter/material.dart';

class AddProduct extends StatefulWidget {
_AddProductState createState() => _AddProductState();
}

class _AddProductState extends State<AddProduct> {
final _formKey = GlobalKey<FormState>();
final TextEditingController _productNameCtrl = TextEditingController();
final TextEditingController _shortDescCtrl = TextEditingController();
final TextEditingController _longDescCtrl = TextEditingController();

Widget _productName() {
return Padding(
padding: const EdgeInsets.only(right: 10, left: 10),
child: TextFormField(
controller: _productNameCtrl,
decoration: InputDecoration(labelText: 'Enter product name:'),
validator: (value) {
if (value.isEmpty) {
return 'This field is required';
}
return null;
},
),
);
}

Widget _image()
{

}

Widget _shortDescription()
{
return Padding(
padding: const EdgeInsets.only(right: 10, left: 10),
child: TextFormField(
controller: _shortDescCtrl,
decoration: InputDecoration(labelText: 'Enter short description:'),
validator: (value) {
if (value.isEmpty) {
return 'This field is required';
}
return null;
},
),
);
}

Widget _longDescription()
{
return Padding(
padding: const EdgeInsets.only(right: 10, left: 10),
child: TextFormField(
controller: _longDescCtrl,
decoration: InputDecoration(labelText: 'Enter long description:'),
validator: (value) {
if (value.isEmpty) {
return 'This field is required';
}
return null;
},
),
);
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Add a new product'),
));
}
}
11 changes: 11 additions & 0 deletions lib/Catalog/ShoppingList.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'package:Bayya/Cart/ShoppingCart.dart';
import 'package:Bayya/Cart/ShoppingCartUpperIcon.dart';
import 'package:Bayya/Catalog/Catalog.dart';
import 'package:Bayya/Catalog/ShoppingListItem.dart';
import 'package:Bayya/Search/SearchPage.dart';
import 'package:Bayya/SideDrawer/SideBar.dart';
import 'package:Bayya/Watchlist/Watchlist.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

Expand All @@ -12,6 +14,15 @@ class ShoppingList extends StatefulWidget {
}

class _ShoppingListState extends State<ShoppingList> {

void initState()
{
super.initState();
context.read<Catalog>().fetchData();
context.read<ShoppingCart>().fetchData();
context.read<Watchlist>().fetchData();
}

Widget _upperSearchIcon(BuildContext context) {
return IconButton(
icon: Icon(Icons.search, color: Colors.white),
Expand Down
46 changes: 33 additions & 13 deletions lib/Catalog/ShoppingListItem.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import 'dart:ui';
import 'package:Bayya/Cart/ShoppingCart.dart';
import 'package:Bayya/Catalog/Catalog.dart';
import 'package:Bayya/ItemWidgets/ShortDescriptionText.dart';
import 'package:Bayya/Product/ProductView.dart';
import 'package:Bayya/User/VendorsList.dart';
import 'package:Bayya/Watchlist/Watchlist.dart';
import 'package:Bayya/WidgetUtils/ShortDescriptionText.dart';
import 'package:Bayya/WidgetUtils/SignInToPerfomAction.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
Expand All @@ -19,6 +22,8 @@ class ShoppingListItem extends StatefulWidget {

class _ShoppingListItemState extends State<ShoppingListItem> {
String _imgURL = "";
String _vendor = 'Vendor not provided';

Future<void> _getImageURL() async {
var result = await FirebaseStorage.instance
.ref()
Expand Down Expand Up @@ -79,27 +84,38 @@ class _ShoppingListItemState extends State<ShoppingListItem> {
}

Widget _vendorText() {
_getVendorName();
return Container(
padding: const EdgeInsets.only(bottom: 4),
child: Text(
Provider.of<Catalog>(context).productsCatalog[widget.productId].vendor,
_vendor,
textAlign: TextAlign.left,
softWrap: true,
),
);
}

Future<void> _getVendorName() async {
var _result = await Provider.of<VendorsList>(context).getVendorNameByUid(
Provider.of<Catalog>(context).productsCatalog[widget.productId].vendor);
_vendor = _result;
}

Widget _buttonToCart() {
return GestureDetector(
onTap: () {
context.read<ShoppingCart>().isInShoppingCart(widget.productId)
? context
.read<ShoppingCart>()
.removeFromShoppingCart(widget.productId)
: context
.read<ShoppingCart>()
.addToShoppingCart(widget.productId);
Scaffold.of(context).showSnackBar(_snackBarCart());
if (FirebaseAuth.instance.currentUser != null) {
context.read<ShoppingCart>().isInShoppingCart(widget.productId)
? context
.read<ShoppingCart>()
.removeFromShoppingCart(widget.productId)
: context
.read<ShoppingCart>()
.addToShoppingCart(widget.productId);
ScaffoldMessenger.of(context).showSnackBar(_snackBarCart());
} else {
showDialog(context: context, builder: (context) => SignInToPerfomAction());
}
},
child: Container(
width: 120,
Expand Down Expand Up @@ -134,9 +150,13 @@ class _ShoppingListItemState extends State<ShoppingListItem> {
: Icon(Icons.favorite_border_outlined);
return GestureDetector(
onTap: () {
context.read<Watchlist>().getWatchlisted(widget.productId)
? context.read<Watchlist>().unWatchlist(widget.productId)
: context.read<Watchlist>().setWatchlisted(widget.productId);
if (FirebaseAuth.instance.currentUser != null) {
context.read<Watchlist>().getWatchlisted(widget.productId)
? context.read<Watchlist>().unWatchlist(widget.productId)
: context.read<Watchlist>().setWatchlisted(widget.productId);
} else {
showDialog(context: context, builder: (context) => SignInToPerfomAction());
}
},
child: Container(
padding: const EdgeInsets.all(4),
Expand Down
Loading

0 comments on commit 1670c25

Please sign in to comment.