Skip to content

Instantly share code, notes, and snippets.

@junjizhi junjizhi/cart_page.dart
Last active Jul 13, 2019

What would you like to do?
Flutter BLoC and Provider: A Shopping Cart Example - Shopping Cart Page
class CartPage extends StatelessWidget {
CartPage({Key key}) : super(key: key);
Widget build(BuildContext context) {
var bloc = Provider.of<CartBloc>(context);
var cart = bloc.cart;
return Scaffold(
appBar: AppBar(
title: Text("Shopping Cart"),
body: ListView.builder(
itemCount: cart.length,
itemBuilder: (context, index) {
int giftIndex = cart.keys.toList()[index];
int count = cart[giftIndex];
return ListTile(
leading: Container(
height: 70,
width: 70,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/${giftIndex + 1}.jpg"),
fit: BoxFit.fitWidth,
borderRadius: BorderRadius.circular(12),
title: Text('Item Count: $count'),
trailing: RaisedButton(
child: Text('Clear'),
color: Theme.of(context).buttonColor,
elevation: 1.0,
splashColor: Colors.blueGrey,
onPressed: () {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.