Fakultas Ilmu Komputer UI

Commit a600d8aa authored by Reka Paska Enda's avatar Reka Paska Enda
Browse files

[GREEN] Menampilkan preorder pada produk

parent 588b5bef
Pipeline #81410 passed with stages
in 3 minutes and 21 seconds
......@@ -154,7 +154,8 @@ class _ItemBody extends StatelessWidget {
(create: (_) => CounterItem(
total: item.quantity,
minimum: 0,
maksimum: item.product.stock),
maksimum: item.product.stock,
preorder: item.product.preorder),
child: _CartDescription(cartItem: item)),
),
),
......@@ -328,7 +329,8 @@ class _ModalCartItem extends StatelessWidget {
create: (_) => CounterItem(
total: cartItem.quantity,
minimum: 0,
maksimum: cartItem.product.stock),
maksimum: cartItem.product.stock,
preorder: cartItem.product.preorder),
child: Builder(
builder: (BuildContext context) {
return Padding(
......@@ -380,10 +382,14 @@ class _ModalCartItem extends StatelessWidget {
.primaryColor,
fontSize: 20),
),
Text(
'Stok: '
'${cartItem.product.stock} ${cartItem.product.unit}',
style: const TextStyle(fontSize: 17),
if (cartItem.product.preorder == false) Text(
'Stok: ${cartItem.product.stock}',
style:
const TextStyle(fontSize: 17),
) else Text(
'Pre-Order: ${cartItem.product.preorder_duration} hari',
style:
const TextStyle(fontSize: 17),
)
],
),
......@@ -496,15 +502,17 @@ class CounterItem extends ChangeNotifier {
int _total;
final int _minimum;
final int _maksimum;
CounterItem({@required total, @required minimum, @required maksimum})
final bool _preorder;
CounterItem({@required total, @required minimum, @required maksimum, @required preorder})
: _total = total,
_maksimum = maksimum,
_minimum = minimum;
_minimum = minimum,
_preorder = preorder;
int get total => _total > _maksimum ? _maksimum : _total;
int get total => (_total > _maksimum && _preorder == false) ? _maksimum : _total;
void increment() {
if (_total + 1 > _maksimum) {
if (_total + 1 > _maksimum && _preorder == false) {
_total = _total;
} else {
_total = _total + 1;
......
......@@ -96,13 +96,20 @@ class _ProductDescription extends StatelessWidget {
color: Colors.black87,
),
),
Text(
'Stock: ${product.stock} ${product.unit}',
if (product.preorder == false) Text(
'Stok: ${product.stock}',
style: const TextStyle(
fontSize: 15,
color: Colors.black54,
),
),
) else Text(
'Pre-Order: ${product.preorder_duration} hari',
style: const TextStyle(
fontSize: 15,
color: Colors.black54,
),
)
,
],
),
Align(
......
......@@ -47,7 +47,8 @@ class _BodyDetailProduct extends StatelessWidget {
create: (context) => CounterItem(
total: 1,
minimum: 1,
maksimum: product.stock),
maksimum: product.stock,
preorder: product.preorder),
child: Builder(
builder: (BuildContext context) {
return LayoutBuilder(
......@@ -104,11 +105,17 @@ class _BodyDetailProduct extends StatelessWidget {
.primaryColor,
fontSize: 20),
),
Text(
'Stok: ${product.stock} ${product.unit}',
if (product.preorder == false) Text(
'Stok: ${product.stock}',
style:
const TextStyle(fontSize: 17),
)
) else Text(
'Pre-Order: ${product.preorder_duration} hari',
style:
const TextStyle(fontSize: 17),
)
,
],
),
),
......
......@@ -16,6 +16,10 @@ class Product extends Equatable {
final String price;
final String unit;
final bool preorder;
final int preorder_duration;
@JsonKey(nullable: true)
final int stock;
......@@ -31,12 +35,15 @@ class Product extends Equatable {
this.subcategoryName,
this.description,
this.price,
this.preorder,
this.preorder_duration,
this.stock,
this.image,
this.unit});
factory Product.fromJson(Map<String, dynamic> json) =>
_$ProductFromJson(json);
Map<String, dynamic> toJson() => _$ProductToJson(this);
@override
......@@ -49,6 +56,8 @@ class Product extends Equatable {
subcategoryName,
description,
price,
preorder,
preorder_duration,
stock,
image,
unit,
......
......@@ -16,6 +16,8 @@ Product _$ProductFromJson(Map<String, dynamic> json) {
subcategoryName: json['subcategory_name'] as String,
description: json['description'] as String,
price: json['price'] as String,
preorder: json['preorder'] as bool,
preorder_duration: json['preorder_duration'] as int,
stock: json['stock'] as int,
image: json['image'] as String,
unit: json['unit'] as String,
......@@ -31,6 +33,8 @@ Map<String, dynamic> _$ProductToJson(Product instance) => <String, dynamic>{
'subcategory_name': instance.subcategoryName,
'description': instance.description,
'price': instance.price,
'preorder': instance.preorder,
'preorder_duration': instance.preorder_duration,
'stock': instance.stock,
'image': instance.image,
'unit': instance.unit,
......
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