Fakultas Ilmu Komputer UI

Commit 208594cd authored by Muhammad Dzikra Muzaki's avatar Muhammad Dzikra Muzaki
Browse files

[GREEN] Add unit column

parent 73070ff6
Pipeline #69503 passed with stages
in 9 minutes and 10 seconds
......@@ -3,18 +3,19 @@ import 'package:intl/intl.dart';
class PriceTextFormatter extends StatelessWidget {
final NumberFormat formatter =
NumberFormat.currency(decimalDigits: 0, symbol: 'Rp');
NumberFormat.currency(decimalDigits: 0, symbol: 'Rp ');
final String price;
final String unit;
final TextStyle style;
final Key keyText;
PriceTextFormatter({Key key, @required this.price, this.style, this.keyText})
PriceTextFormatter({Key key, @required this.price, this.unit, this.style, this.keyText})
: assert(price != null),
super(key: key);
@override
Widget build(BuildContext context) {
return Text(
formatter.format(double.parse(price)),
unit != null ? formatter.format(double.parse(price)) + ' / ' + unit : formatter.format(double.parse(price)),
key: keyText,
overflow: TextOverflow.ellipsis,
maxLines: 1,
......
......@@ -195,6 +195,7 @@ class _CartDescription extends StatelessWidget {
),
PriceTextFormatter(
price: '${cartItem.product.price}',
unit: '${cartItem.product.unit}',
),
],
),
......@@ -248,7 +249,7 @@ class _CartDescription extends StatelessWidget {
fontSize: 15),
children: <TextSpan>[
TextSpan(
text: '${cartItem.quantity}',
text: '${cartItem.quantity} ${cartItem.product.unit}',
style: TextStyle(
color: Theme.of(context).primaryColor,
fontSize: 16,
......@@ -373,6 +374,7 @@ class _ModalCartItem extends StatelessWidget {
children: <Widget>[
PriceTextFormatter(
price: cartItem.product.price,
unit: cartItem.product.unit,
style: TextStyle(
color: Theme.of(context)
.primaryColor,
......@@ -380,7 +382,7 @@ class _ModalCartItem extends StatelessWidget {
),
Text(
'Stok: '
'${cartItem.product.stock}',
'${cartItem.product.stock} ${cartItem.product.unit}',
style: const TextStyle(fontSize: 17),
)
],
......
......@@ -156,6 +156,7 @@ class ProductGrid extends StatelessWidget {
),
PriceTextFormatter(
price: _product.price,
unit: _product.unit,
),
],
),
......
......@@ -90,13 +90,14 @@ class _ProductDescription extends StatelessWidget {
children: <Widget>[
PriceTextFormatter(
price: '${product.price}',
unit: '${product.unit}',
style: const TextStyle(
fontSize: 15,
color: Colors.black87,
),
),
Text(
'Stock: ${product.stock}',
'Stock: ${product.stock} ${product.unit}',
style: const TextStyle(
fontSize: 15,
color: Colors.black54,
......
......@@ -98,13 +98,14 @@ class _BodyDetailProduct extends StatelessWidget {
children: <Widget>[
PriceTextFormatter(
price: product.price,
unit: product.unit,
style: TextStyle(
color: Theme.of(context)
.primaryColor,
fontSize: 20),
),
Text(
'Stok: ${product.stock}',
'Stok: ${product.stock} ${product.unit}',
style:
const TextStyle(fontSize: 17),
)
......
......@@ -14,6 +14,7 @@ class Product extends Equatable {
final String subcategoryName;
final String description;
final String price;
final String unit;
@JsonKey(nullable: true)
final int stock;
......@@ -31,7 +32,8 @@ class Product extends Equatable {
this.description,
this.price,
this.stock,
this.image});
this.image,
this.unit});
factory Product.fromJson(Map<String, dynamic> json) =>
_$ProductFromJson(json);
......@@ -49,5 +51,6 @@ class Product extends Equatable {
price,
stock,
image,
unit,
];
}
......@@ -18,6 +18,7 @@ Product _$ProductFromJson(Map<String, dynamic> json) {
price: json['price'] as String,
stock: json['stock'] as int,
image: json['image'] as String,
unit: json['unit'] as String,
);
}
......@@ -32,4 +33,5 @@ Map<String, dynamic> _$ProductToJson(Product instance) => <String, dynamic>{
'price': instance.price,
'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