84 lines
2.5 KiB
Dart
84 lines
2.5 KiB
Dart
import 'package:fcs/model/product_model.dart';
|
|
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';
|
|
import 'package:fcs/theme/theme.dart';
|
|
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")),
|
|
DataColumn(label: LocalText(context, "products.prices"),numeric: true),
|
|
],
|
|
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();
|
|
}
|
|
}
|