Last active
July 13, 2019 21:18
-
-
Save junjizhi/47a2f29f4fe690ce9e7a5e9f25ce49b9 to your computer and use it in GitHub Desktop.
Flutter BLoC and Provider: A Shopping Cart Example - Shopping Cart Page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/junjizhi/flutter-shopping-cart | |
class CartPage extends StatelessWidget { | |
CartPage({Key key}) : super(key: key); | |
@override | |
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: () { | |
bloc.clear(giftIndex); | |
}, | |
), | |
); | |
}, | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment