Fakultas Ilmu Komputer UI

Commit 8a1aeea9 authored by Tsamara Esperanti Erwin's avatar Tsamara Esperanti Erwin 🦄
Browse files

Merge branch 'coldfix-cart' into 'staging'

Coldfix cart

See merge request ppl-fasilkom-ui/itproject-2020/group-b/pilar-mobile!98
parents b64af4a9 c4fd8505
......@@ -135,7 +135,7 @@ class _KeranjangBody extends StatelessWidget {
class _ItemBody extends StatelessWidget {
final CartItem item;
static const int int64MaxValue = 9223372036854775807;
const _ItemBody({Key key, @required this.item}) : super(key: key);
@override
Widget build(BuildContext context) {
......@@ -152,7 +152,14 @@ class _ItemBody extends StatelessWidget {
Expanded(
child: Padding(
padding: const EdgeInsets.fromLTRB(20, 8, 15, 8),
child: _CartDescription(cartItem: item),
child: ChangeNotifierProvider<CounterItem>
(create: (_) => CounterItem(
total: item.quantity,
minimum: 0,
maksimum: item.product.preOrder
? int64MaxValue
: item.product.stock),
child: _CartDescription(cartItem: item)),
),
),
]));
......@@ -175,24 +182,54 @@ class _CartDescription extends StatelessWidget {
children: <Widget>[
Expanded(
flex: 5,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Text(
'${cartItem.product.name}',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Text(
'${cartItem.product.name}',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
PriceTextFormatter(
price: '${cartItem.product.price}',
),
if (cartItem.product.preOrder) const Text('Preorder')
],
),
const Padding(padding: EdgeInsets.only(bottom: 2)),
PriceTextFormatter(
price: '${cartItem.product.price}',
Column(
children: [
Consumer<CounterItem>(
builder: (_, counter, __) =>
GestureDetector(
onTap: () {
context
.read<CounterItem>()
.toZero();
updateCartToZero(context, counter);
},
child: Container(
width: 35,
height: 35,
decoration: BoxDecoration(
color: Theme.of(context).primaryColor,
shape: BoxShape.circle,
),
margin: EdgeInsets.symmetric(vertical: 3.0),
child: const Icon(Icons.delete_forever,
color: Colors.white,),
),
),
),
],
),
if (cartItem.product.preOrder) const Text('Preorder')
],
),
),
......@@ -200,7 +237,6 @@ class _CartDescription extends StatelessWidget {
flex: 4,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Flexible(
child: Column(
......@@ -240,28 +276,34 @@ class _CartDescription extends StatelessWidget {
],
),
),
Flexible(
child: RaisedButton(
onPressed: () {
showModalBottomSheet(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
top: Radius.circular(25))),
context: context,
builder: (BuildContext context) {
return _ModalCartItem(cartItem: cartItem);
});
},
color: Theme.of(context).primaryColor,
child: const Text(
'Ubah',
textAlign: TextAlign.right,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w700,
Column(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Flexible(
child: RaisedButton(
onPressed: () {
showModalBottomSheet(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
top: Radius.circular(25))),
context: context,
builder: (BuildContext context) {
return _ModalCartItem(cartItem: cartItem);
});
},
color: Theme.of(context).primaryColor,
child: const Text(
'Ubah',
textAlign: TextAlign.right,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w700,
),
),
),
),
),
],
)
],
),
......@@ -269,6 +311,11 @@ class _CartDescription extends StatelessWidget {
],
);
}
void updateCartToZero(BuildContext context, CounterItem counter) {
BlocProvider.of<CartBloc>(context)
.add(UpdateCartItem(counter.total, cartItem.product.id));
}
}
class _ModalCartItem extends StatelessWidget {
......@@ -356,8 +403,9 @@ class _ModalCartItem extends StatelessWidget {
Ink(
width: 30,
height: 30,
decoration: const ShapeDecoration(
color: Colors.red,
decoration: ShapeDecoration(
color: Theme.of(context)
.primaryColor,
shape: CircleBorder(),
),
child: IconButton(
......@@ -379,8 +427,9 @@ class _ModalCartItem extends StatelessWidget {
Ink(
width: 30,
height: 30,
decoration: const ShapeDecoration(
color: Colors.green,
decoration: ShapeDecoration(
color: Theme.of(context)
.primaryColor,
shape: CircleBorder(),
),
child: IconButton(
......@@ -442,7 +491,6 @@ class _ModalCartItem extends StatelessWidget {
),
);
}
void updateCart(BuildContext context, CounterItem counter) {
BlocProvider.of<CartBloc>(context)
.add(UpdateCartItem(counter.total, cartItem.product.id));
......@@ -478,4 +526,9 @@ class CounterItem extends ChangeNotifier {
notifyListeners();
}
}
void toZero() {
_total = 0;
notifyListeners();
}
}
......@@ -124,8 +124,9 @@ class _BodyDetailProduct extends StatelessWidget {
width: 30,
height: 30,
decoration:
const ShapeDecoration(
color: Colors.red,
ShapeDecoration(
color: Theme.of(context)
.primaryColor,
shape: CircleBorder(),
),
child: IconButton(
......@@ -147,8 +148,9 @@ class _BodyDetailProduct extends StatelessWidget {
Ink(
width: 30,
height: 30,
decoration: const ShapeDecoration(
color: Colors.green,
decoration: ShapeDecoration(
color: Theme.of(context)
.primaryColor,
shape: CircleBorder(),
),
child: IconButton(
......
......@@ -611,6 +611,34 @@ void main() {
await tester.pump(Duration(seconds: 5));
});
testWidgets('Test Widget Loaded tap Trash Can Icon', (WidgetTester tester) async {
when(cartBloc.state).thenAnswer((_) => CartLoaded([
CartItem(
'test',
1,
Product(
image: null,
categoryName: 'catName',
category: 'catId',
name: 'kue',
preOrder: false,
id: '1',
description: 'aaaa',
price: '200000',
stock: 2,
subcategory: 'subCatId',
subcategoryName: 'subCatName'))
], '200000', 1));
await tester.pumpWidget(testedWidget);
expect(find.text('Keranjang'), findsOneWidget);
expect(find.text('kue'), findsOneWidget);
expect(find.byType(PriceTextFormatter), findsNWidgets(3));
expect(find.byIcon(Icons.delete_forever), findsOneWidget);
await tester.tap(find.byIcon(Icons.delete_forever));
await tester.pump(Duration(seconds: 5));
verify(cartBloc.add(UpdateCartItem(0, '1'))).called(1);
});
testWidgets('Test Widget Loaded tap Add', (WidgetTester tester) async {
when(cartBloc.state).thenAnswer((_) => CartLoaded([
CartItem(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment