Fakultas Ilmu Komputer UI
Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ppl-fasilkom-ui
IT Project 2020
Group B
pilar-mobile
Commits
8a1aeea9
Commit
8a1aeea9
authored
Dec 10, 2020
by
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
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
lib/Pages/Cart/cart.dart
View file @
8a1aeea9
...
...
@@ -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
();
}
}
lib/Pages/Product/detail_product.dart
View file @
8a1aeea9
...
...
@@ -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
(
...
...
test/cart_page_test.dart
View file @
8a1aeea9
...
...
@@ -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
(
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment