Open dassaniansh opened 4 years ago
//Code for cart.dart
import 'package:flutter/material.dart';
import 'cart_products.dart';
class Cart extends StatefulWidget {
@override
_CartState createState() => _CartState();
}
class _CartState extends State<Cart> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
elevation: 0.1,
backgroundColor: Colors.red,
title: Text('Cart'),
actions: <Widget>[
IconButton(
icon: Icon(
Icons.close,
color: Colors.white,
),
onPressed: () {
Navigator.pop(context);
},
),
],
),
body: Cart_products(),
bottomNavigationBar: Container(
color: Colors.white70,
child: Row(
children: <Widget>[
Expanded(
child: ListTile(
title: Text('Total Amount'),
subtitle: Text('your amount in \$/rs'),
),
),
Expanded(
child: MaterialButton(
onPressed: () {},
child: Text(
'Check Out',
style: TextStyle(color: Colors.white),
),
color: Colors.red,
),
)
],
),
),
);
}
}
//code for cart_products.dart
import 'package:flutter/material.dart';
class Cart_products extends StatefulWidget {
@override
_Cart_productsState createState() => _Cart_productsState();
}
class _Cart_productsState extends State<Cart_products> {
var products_purchased=[{
'products': 'flour',
'qty':'5',
'price':'50',
}
];
@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: products_purchased.length,
itemBuilder: (context, index) {
return Cart_element(
products:products_purchased[index]['products'] ,
qty:products_purchased[index]['qty'] ,
price:products_purchased[index]['price']
);
}
);
}
}
class Cart_element extends StatelessWidget {
Cart_element({this.products,this.qty,this.price});
final products ;
final qty;
final price;
@override
Widget build(BuildContext context) {
return Card(
child: ListTile(
leading: Image.network('http://pngimg.com/uploads/flour/flour_PNG25.png',width: 80.0,height: 80.0),
title: Text(
products
),
subtitle: Column(
children: <Widget>[
Row(
children: <Widget>[
Expanded(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'Qty:',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'value',
style: TextStyle(
color: Colors.red,
),
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'Price:',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'Price',
style: TextStyle(
color: Colors.red,
),
),
),
),
// Text(
// price
// )
],
)
],
),
),
);
}
}
Above are the 2 screens for cart functionality ..the only thing left is to add the list after fetching
Add functionality similar to E-Commerce platforms.