Files
fcs/lib/widget/products_price_table.dart

84 lines
2.6 KiB
Dart
Raw Normal View History

2020-05-31 15:00:11 +06:30
import 'package:fcs/model/product_model.dart';
2020-05-29 07:45:27 +06:30
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
import 'package:fcs/model/language_model.dart';
2020-08-30 21:26:37 +06:30
import 'package:fcs/fcs/common/theme.dart';
2020-05-29 07:45:27 +06:30
import 'package:fcs/vo/product.dart';
import 'package:fcs/widget/local_text.dart';
import 'package:fcs/widget/localization/app_translations.dart';
class ProductPriceTable extends StatefulWidget {
const ProductPriceTable();
@override
_ProductPriceTableState createState() => _ProductPriceTableState();
}
class _ProductPriceTableState extends State<ProductPriceTable> {
final numberFormatter = new NumberFormat("#,###");
var dateFormatter = new DateFormat('dd MMM yyyy\nhh:mm:ss a');
@override
Widget build(BuildContext context) {
var productModel = Provider.of<ProductModel>(context);
return Scaffold(
appBar: AppBar(
backgroundColor: primaryColor,
title: Text(
AppTranslations.of(context).text("products.prices"),
style: Provider.of<LanguageModel>(context).isEng
? TextStyle(fontSize: 18)
: TextStyle(fontSize: 18, fontFamily: 'MyanmarUnicode'),
),
),
body: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: DataTable(
columns: [
DataColumn(label: LocalText(context, "product.update.date")),
DataColumn(label: LocalText(context, "prodcuts")),
2020-08-30 21:26:37 +06:30
DataColumn(
label: LocalText(context, "products.prices"), numeric: true),
2020-05-29 07:45:27 +06:30
],
rows: getProductRow(productModel.getPrices),
),
),
),
);
}
List<DataRow> getProductRow(List<ProductPrice> productPrices) {
ProductPrice prev;
bool isOdd = false;
return productPrices.map((p) {
if (prev != null && prev.date.compareTo(p.date) != 0) {
isOdd = !isOdd;
}
var r = DataRow(
cells: [
DataCell(
new Text(dateFormatter.format(p.date),
style: isOdd ? textStyle : textStyleOdd),
),
DataCell(
new Text(
p.name,
style: isOdd ? textStyle : textStyleOdd,
),
),
DataCell(
new Text(numberFormatter.format(p.price),
style: isOdd ? textStyle : textStyleOdd),
),
],
);
prev = p;
return r;
}).toList();
}
}