-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3754935
commit dc1acd3
Showing
5 changed files
with
117 additions
and
3 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
org.gradle.jvmargs=-Xmx1536M | ||
android.useAndroidX=true | ||
android.enableJetifier=true | ||
android.enableR8=true |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import 'package:bloc_shopping/blocs/cart_bloc.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class CartScreen extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: Text("Sepet"), | ||
), | ||
body: StreamBuilder( | ||
stream: cartBloc.getStream, | ||
initialData: cartBloc.getCart(), | ||
builder: (context, snapshot) { | ||
return snapshot.data.length > 0 | ||
? buildCart(snapshot) | ||
: Center( | ||
child: Text("Empty"), | ||
); | ||
}, | ||
), | ||
); | ||
} | ||
|
||
Widget buildCart(AsyncSnapshot snapshot) { | ||
return ListView.builder( | ||
itemCount: snapshot.data.length, | ||
itemBuilder: (BuildContext context, index) { | ||
final cart = snapshot.data; | ||
return ListTile( | ||
title: Text(cart[index].product.name), | ||
subtitle: Text( | ||
cart[index].product.price.toString(), | ||
), | ||
trailing: IconButton( | ||
icon: Icon(Icons.remove_shopping_cart), | ||
onPressed: () { | ||
cartBloc.removeFromCart(cart[index]); | ||
}, | ||
), | ||
); | ||
}); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import 'package:bloc_shopping/blocs/cart_bloc.dart'; | ||
import 'package:bloc_shopping/blocs/product_bloc.dart'; | ||
import 'package:bloc_shopping/models/cart_item.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class ProductListScreen extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
actions: [ | ||
IconButton( | ||
onPressed: () => Navigator.pushNamed(context, "/cart"), | ||
icon: Icon(Icons.shopping_cart), | ||
), | ||
], | ||
), | ||
body: buildProductList(), | ||
); | ||
} | ||
|
||
Widget buildProductList() { | ||
return StreamBuilder( | ||
initialData: productBloc.getAll(), | ||
stream: productBloc.getStream, | ||
builder: (context, snapshot) { | ||
return snapshot.data.length > 0 | ||
? buildProductListItem(snapshot) | ||
: Center( | ||
child: Text("Loading..."), | ||
); | ||
}, | ||
); | ||
} | ||
|
||
Widget buildProductListItem(AsyncSnapshot snapshot) { | ||
return ListView.builder( | ||
itemCount: snapshot.data.length, | ||
itemBuilder: (BuildContext context, index) { | ||
final list = snapshot.data; | ||
|
||
return ListTile( | ||
title: Text( | ||
list[index].name, | ||
), | ||
subtitle: Text( | ||
list[index].price.toString(), | ||
), | ||
trailing: IconButton( | ||
icon: Icon(Icons.add_shopping_cart), | ||
onPressed: () { | ||
cartBloc.addToCart( | ||
CartItem(list[index], 1), | ||
); | ||
}, | ||
), | ||
); | ||
}, | ||
); | ||
} | ||
} |