Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cart System Implemented #260

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
14 changes: 11 additions & 3 deletions lib/model/product_model.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

class Product {
Product({
this.text,
Expand All @@ -6,11 +7,16 @@ class Product {
this.image,
this.seller,
this.height,
this.id,
this.dbId
});

factory Product.fromJson(dynamic productData) {
factory Product.fromJson(Map<String,dynamic> productData) {
// log('prodcut id : ${productData['_id'].runtimeType}');
return Product(
amount: productData['amount'].toString(),
amount: productData['amount'],
id : productData['id'],
dbId: productData['_id'],
image: productData['image'].toString() == ''
? 'assets/items/${productData['id']}.png'
: productData['image'].toString(),
Expand All @@ -25,8 +31,10 @@ class Product {

final String? text;
final String? owner;
final String? amount;
final int? amount;
final String? image;
final String? seller;
final int? height;
final int? id;
final String? dbId;
}
11 changes: 11 additions & 0 deletions lib/services/product_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,15 @@ class ProductService {
)
.toList();
}

Future<Product> getProductDetails(String index) async {
print('index : $index');
final http.Response response = await http.get(
Uri.parse('https://himanshusharma89-api.herokuapp.com/relic_bazaar/products/$index'),
);
final Product product = Product.fromJson(json.decode(response.body));
print(product.text);
return product;
}

}
203 changes: 112 additions & 91 deletions lib/views/cart_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:relic_bazaar/helpers/constants.dart';
import 'package:relic_bazaar/widgets/payment/cart_item.dart';
import 'package:relic_bazaar/widgets/payment/payment_window.dart';
import 'package:relic_bazaar/widgets/retro_button.dart';
import 'package:shared_preferences/shared_preferences.dart';

class Cart extends StatefulWidget {
const Cart({
Expand All @@ -17,109 +18,129 @@ class Cart extends StatefulWidget {
}

class _CartState extends State<Cart> {

Future<List<String>> getMyCart() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.getStringList('myCart') ?? <String>[];
}

@override
Widget build(BuildContext context) {
final double height = MediaQuery.of(context).size.height;
final double width = MediaQuery.of(context).size.width;
return Padding(
padding: const EdgeInsets.symmetric(
horizontal: 12,
),
child: ListView(
children: <Widget>[
SizedBox(
height: height * 0.01,
),
const Text(
'Your Cart',
style: TextStyle(
fontSize: 30,
color: Colors.white,
fontWeight: FontWeight.w700,
return FutureBuilder<List<String>>(
future: getMyCart(),
builder: (_ , AsyncSnapshot<List<String>> snapShot){
if(snapShot.hasData){
List<String> myCart = snapShot.data ?? <String>[];
return Padding(
padding: const EdgeInsets.symmetric(
horizontal: 12,
),
textAlign: TextAlign.left,
),
SizedBox(
height: height * 0.01,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
GestureDetector(
onTap: () {
setState(() {
widget.pageController!.jumpTo(0);
});
},
child: RelicBazaarStackedView(
upperColor: Colors.white,
height: height * 0.045,
width: width * 0.4,
borderColor: Colors.white,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: const <Widget>[
Icon(
Icons.arrow_back,
size: 20,
child: ListView(
children: <Widget>[
SizedBox(
height: height * 0.01,
),
const Text(
'Your Cart',
style: TextStyle(
fontSize: 30,
color: Colors.white,
fontWeight: FontWeight.w700,
),
textAlign: TextAlign.left,
),
SizedBox(
height: height * 0.01,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
GestureDetector(
onTap: () {
setState(() {
widget.pageController!.jumpTo(0);
});
},
child: RelicBazaarStackedView(
upperColor: Colors.white,
height: height * 0.045,
width: width * 0.4,
borderColor: Colors.white,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: const <Widget>[
Icon(
Icons.arrow_back,
size: 20,
),
Text(
' back to shop',
style: TextStyle(
fontFamily: 'pix M 8pt',
fontSize: 15,
fontWeight: FontWeight.bold,
color: RelicColors.primaryBlack,
),
),
],
),
),
Text(
' back to shop',
style: TextStyle(
fontFamily: 'pix M 8pt',
fontSize: 15,
fontWeight: FontWeight.bold,
color: RelicColors.primaryBlack,
),
RelicBazaarStackedView(
upperColor: Colors.black,
lowerColor: Colors.white,
height: height * 0.045,
width: width * 0.22,
child: Center(
child: Text(
myCart.length.toString(),
style: const TextStyle(
fontFamily: 'pix M 8pt',
fontSize: 15,
color: Colors.white,
),
textAlign: TextAlign.center,
),
),
],
),
),
],
),
const Divider(
color: Colors.white,
thickness: 0.9,
),
),
RelicBazaarStackedView(
upperColor: Colors.black,
lowerColor: Colors.white,
height: height * 0.045,
width: width * 0.22,
child: const Center(
child: Text(
'5 items',
style: TextStyle(
fontFamily: 'pix M 8pt',
fontSize: 15,
color: Colors.white,
Column(
children: <Widget>[
ListView.builder(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: myCart.length,
itemBuilder: (BuildContext context, int index) {
return CartItem(index : myCart[index], pageController: widget.pageController,);
},
),
textAlign: TextAlign.center,
),
Align(
alignment: Alignment.bottomCenter,
child: PaymentWindow(),
),
SizedBox(
height: height * 0.08,
),
],
),
),
],
),
const Divider(
color: Colors.white,
thickness: 0.9,
),
Column(
children: <Widget>[
ListView.builder(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: 5,
itemBuilder: (BuildContext context, int index) {
return CartItem();
},
),
Align(
alignment: Alignment.bottomCenter,
child: PaymentWindow(),
),
SizedBox(
height: height * 0.08,
),
],
],
),
);
}
return const Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
),
],
),
);

}
);
}
}
Loading