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/fcs/common/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 { final numberFormatter = new NumberFormat("#,###"); var dateFormatter = new DateFormat('dd MMM yyyy\nhh:mm:ss a'); @override Widget build(BuildContext context) { var productModel = Provider.of(context); return Scaffold( appBar: AppBar( backgroundColor: primaryColor, title: Text( AppTranslations.of(context).text("products.prices"), style: Provider.of(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 getProductRow(List 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(); } }