fix number formatting

This commit is contained in:
Sai Naw Wun
2020-10-22 05:27:03 +06:30
parent e5540c5491
commit bbacbd151a
5 changed files with 40 additions and 23 deletions

View File

@@ -1,5 +1,3 @@
import 'dart:convert';
class CargoType {
String id;
String name;

View File

@@ -38,7 +38,7 @@ class Invoice {
CargoType existing = cargoTypes.firstWhere((wc) => wc.id == tc.id);
existing.weight += tc.weight;
} else {
cargoTypes.add(tc);
cargoTypes.add(tc.clone());
}
actualWeight += tc.weight;
});

View File

@@ -8,9 +8,11 @@ import 'package:fcs/pages/main/util.dart';
import 'package:fcs/pages/widgets/local_text.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
typedef OnDiscountSelected(Discount discount);
typedef OnDeliveryFeeSelected(bool selected);
final formatter = new NumberFormat("#,###.00");
class InvoiceCargoTable extends StatelessWidget {
final Invoice invoice;
@@ -46,10 +48,11 @@ class InvoiceCargoTable extends StatelessWidget {
Expanded(flex: 2, child: Text('${cargo.name}')),
Expanded(
flex: 2,
child: Text('${cargo.calWeight} x ${cargo.calRate}',
child: Text(
'${cargo.calWeight.toStringAsFixed(2)} x ${cargo.calRate.toStringAsFixed(2)}',
textAlign: TextAlign.center)),
Expanded(
child: Text('\$ $amount',
child: Text('\$ ${amount.toStringAsFixed(2)}',
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 15,
@@ -118,7 +121,7 @@ class InvoiceCargoTable extends StatelessWidget {
SizedBox(width: 40),
Expanded(
child: Text(
'\$ $total',
'\$ ${total.toStringAsFixed(2)}',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
textAlign: TextAlign.end,
))
@@ -155,7 +158,8 @@ class InvoiceCargoTable extends StatelessWidget {
}
}),
Expanded(
child: Text('\$ ( ${invoice.getDiscount()} )',
child:
Text('\$ ( ${invoice.getDiscount().toStringAsFixed(2)} )',
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 15,
@@ -185,7 +189,7 @@ class InvoiceCargoTable extends StatelessWidget {
),
SizedBox(width: 40),
Expanded(
child: Text('\$ ${invoice.getCustomFee()}',
child: Text('\$ ${invoice.getCustomFee().toStringAsFixed(2)}',
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 15,
@@ -215,7 +219,8 @@ class InvoiceCargoTable extends StatelessWidget {
),
SizedBox(width: 50),
Expanded(
child: Text('\$ ${invoice.handlingFee?.toString() ?? ""}',
child: Text(
'\$ ${invoice.getHandlingFee().toStringAsFixed(2) ?? ""}',
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 15,
@@ -253,7 +258,8 @@ class InvoiceCargoTable extends StatelessWidget {
activeColor: primaryColor,
),
Expanded(
child: Text('\$ ${invoice.getDeliveryFee()}',
child:
Text('\$ ${invoice.getDeliveryFee().toStringAsFixed(2)}',
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 15,
@@ -297,7 +303,8 @@ class InvoiceCargoTable extends StatelessWidget {
),
),
Expanded(
child: Text('\$ ${invoice.getNetAmount(rate)}',
child: Text(
'\$ ${invoice.getNetAmount(rate).toStringAsFixed(2)}',
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 18,
@@ -327,7 +334,8 @@ class InvoiceCargoTable extends StatelessWidget {
),
),
Expanded(
child: Text('\$ ${invoice.getTotalBalance(rate)}',
child: Text(
'\$ ${invoice.getTotalBalance(rate).toStringAsFixed(2)}',
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 18,

View File

@@ -1,5 +1,6 @@
import 'package:fcs/domain/entities/carton.dart';
import 'package:fcs/domain/entities/package.dart';
import 'package:fcs/domain/entities/rate.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/widgets/local_text.dart';
import 'package:fcs/pages/widgets/local_title.dart';
@@ -11,8 +12,9 @@ typedef OnSelect = Function(Carton carton, bool checked);
class InvoiceCartonTable extends StatelessWidget {
final List<Carton> cartons;
final OnSelect onSelect;
final Rate rate;
const InvoiceCartonTable({Key key, this.cartons, this.onSelect})
const InvoiceCartonTable({Key key, this.cartons, this.onSelect, this.rate})
: super(key: key);
@override
@@ -88,6 +90,14 @@ class InvoiceCartonTable extends StatelessWidget {
"${p.value?.length ?? ""} x ${p.value?.width ?? ""} x ${p.value?.height ?? ""}",
style: textStyle,
),
new Text(
"${p.value?.getShipmentWeight(rate.volumetricRatio)?.toStringAsFixed(2) ?? "0"} lb",
style: textStyle,
),
new Text(
"${p.value?.actualWeight?.toStringAsFixed(2) ?? "0"} lb (Actual)",
style: textStyle,
),
],
),
)

View File

@@ -169,6 +169,7 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
);
final cartonTable = InvoiceCartonTable(
cartons: _cartons,
rate: rate,
onSelect: (c, checked) {
setState(() {
c.isChecked = checked;