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 !98
parents b64af4a9 c4fd8505
Pipeline #61679 passed with stages
in 15 minutes and 46 seconds
...@@ -135,7 +135,7 @@ class _KeranjangBody extends StatelessWidget { ...@@ -135,7 +135,7 @@ class _KeranjangBody extends StatelessWidget {
class _ItemBody extends StatelessWidget { class _ItemBody extends StatelessWidget {
final CartItem item; final CartItem item;
static const int int64MaxValue = 9223372036854775807;
const _ItemBody({Key key, @required this.item}) : super(key: key); const _ItemBody({Key key, @required this.item}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -152,7 +152,14 @@ class _ItemBody extends StatelessWidget { ...@@ -152,7 +152,14 @@ class _ItemBody extends StatelessWidget {
Expanded( Expanded(
child: Padding( child: Padding(
padding: const EdgeInsets.fromLTRB(20, 8, 15, 8), 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 { ...@@ -175,24 +182,54 @@ class _CartDescription extends StatelessWidget {
children: <Widget>[ children: <Widget>[
Expanded( Expanded(
flex: 5, flex: 5,
child: Column( child: Row(
crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisAlignment: MainAxisAlignment.start, children: [
children: <Widget>[ Column(
Text( crossAxisAlignment: CrossAxisAlignment.start,
'${cartItem.product.name}', mainAxisAlignment: MainAxisAlignment.start,
maxLines: 1, children: <Widget>[
overflow: TextOverflow.ellipsis, Text(
style: const TextStyle( '${cartItem.product.name}',
fontSize: 18, maxLines: 1,
fontWeight: FontWeight.bold, 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)), Column(
PriceTextFormatter( children: [
price: '${cartItem.product.price}', 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 { ...@@ -200,7 +237,6 @@ class _CartDescription extends StatelessWidget {
flex: 4, flex: 4,
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[ children: <Widget>[
Flexible( Flexible(
child: Column( child: Column(
...@@ -240,28 +276,34 @@ class _CartDescription extends StatelessWidget { ...@@ -240,28 +276,34 @@ class _CartDescription extends StatelessWidget {
], ],
), ),
), ),
Flexible( Column(
child: RaisedButton( crossAxisAlignment: CrossAxisAlignment.end,
onPressed: () { mainAxisAlignment: MainAxisAlignment.spaceEvenly,
showModalBottomSheet( children: [
shape: const RoundedRectangleBorder( Flexible(
borderRadius: BorderRadius.vertical( child: RaisedButton(
top: Radius.circular(25))), onPressed: () {
context: context, showModalBottomSheet(
builder: (BuildContext context) { shape: const RoundedRectangleBorder(
return _ModalCartItem(cartItem: cartItem); borderRadius: BorderRadius.vertical(
}); top: Radius.circular(25))),
}, context: context,
color: Theme.of(context).primaryColor, builder: (BuildContext context) {
child: const Text( return _ModalCartItem(cartItem: cartItem);
'Ubah', });
textAlign: TextAlign.right, },
style: TextStyle( color: Theme.of(context).primaryColor,
color: Colors.white, child: const Text(
fontWeight: FontWeight.w700, 'Ubah',
textAlign: TextAlign.right,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w700,
),
),
), ),
), ),
), ],
) )
], ],
), ),
...@@ -269,6 +311,11 @@ class _CartDescription extends StatelessWidget { ...@@ -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 { class _ModalCartItem extends StatelessWidget {
...@@ -356,8 +403,9 @@ class _ModalCartItem extends StatelessWidget { ...@@ -356,8 +403,9 @@ class _ModalCartItem extends StatelessWidget {
Ink( Ink(
width: 30, width: 30,
height: 30, height: 30,
decoration: const ShapeDecoration( decoration: ShapeDecoration(
color: Colors.red, color: Theme.of(context)
.primaryColor,
shape: CircleBorder(), shape: CircleBorder(),
), ),
child: IconButton( child: IconButton(
...@@ -379,8 +427,9 @@ class _ModalCartItem extends StatelessWidget { ...@@ -379,8 +427,9 @@ class _ModalCartItem extends StatelessWidget {
Ink( Ink(
width: 30, width: 30,
height: 30, height: 30,
decoration: const ShapeDecoration( decoration: ShapeDecoration(
color: Colors.green, color: Theme.of(context)
.primaryColor,
shape: CircleBorder(), shape: CircleBorder(),
), ),
child: IconButton( child: IconButton(
...@@ -442,7 +491,6 @@ class _ModalCartItem extends StatelessWidget { ...@@ -442,7 +491,6 @@ class _ModalCartItem extends StatelessWidget {
), ),
); );
} }
void updateCart(BuildContext context, CounterItem counter) { void updateCart(BuildContext context, CounterItem counter) {
BlocProvider.of<CartBloc>(context) BlocProvider.of<CartBloc>(context)
.add(UpdateCartItem(counter.total, cartItem.product.id)); .add(UpdateCartItem(counter.total, cartItem.product.id));
...@@ -478,4 +526,9 @@ class CounterItem extends ChangeNotifier { ...@@ -478,4 +526,9 @@ class CounterItem extends ChangeNotifier {
notifyListeners(); notifyListeners();
} }
} }
void toZero() {
_total = 0;
notifyListeners();
}
} }
...@@ -124,8 +124,9 @@ class _BodyDetailProduct extends StatelessWidget { ...@@ -124,8 +124,9 @@ class _BodyDetailProduct extends StatelessWidget {
width: 30, width: 30,
height: 30, height: 30,
decoration: decoration:
const ShapeDecoration( ShapeDecoration(
color: Colors.red, color: Theme.of(context)
.primaryColor,
shape: CircleBorder(), shape: CircleBorder(),
), ),
child: IconButton( child: IconButton(
...@@ -147,8 +148,9 @@ class _BodyDetailProduct extends StatelessWidget { ...@@ -147,8 +148,9 @@ class _BodyDetailProduct extends StatelessWidget {
Ink( Ink(
width: 30, width: 30,
height: 30, height: 30,
decoration: const ShapeDecoration( decoration: ShapeDecoration(
color: Colors.green, color: Theme.of(context)
.primaryColor,
shape: CircleBorder(), shape: CircleBorder(),
), ),
child: IconButton( child: IconButton(
......
...@@ -611,6 +611,34 @@ void main() { ...@@ -611,6 +611,34 @@ void main() {
await tester.pump(Duration(seconds: 5)); 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 { testWidgets('Test Widget Loaded tap Add', (WidgetTester tester) async {
when(cartBloc.state).thenAnswer((_) => CartLoaded([ when(cartBloc.state).thenAnswer((_) => CartLoaded([
CartItem( 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