import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; import 'package:fcs/model/chart_model.dart'; import 'package:fcs/fcs/common/helpers/theme.dart'; import 'package:fcs/vo/po_do_count.dart'; import 'package:fcs/widget/local_text.dart'; import 'package:fcs/widget/my_data_table.dart'; import 'package:fcs/widget/progress.dart'; class DOLineDetail extends StatefulWidget { const DOLineDetail(); @override _DOLineDetailState createState() => _DOLineDetailState(); } class _DOLineDetailState extends State { final numberFormatter = new NumberFormat("#,###"); var dateFormatter = new DateFormat('dd MMM yyyy'); bool _isLoading = false; @override void initState() { super.initState(); } @override Widget build(BuildContext context) { var chartModel = Provider.of(context); return LocalProgress( inAsyncCall: _isLoading, child: Scaffold( appBar: AppBar( backgroundColor: primaryColor, title: LocalText( context, 'do.counts', color: Colors.white, fontSize: 18, ), ), body: Container( child: ListView( children: [ Column( children: [ Container( padding: EdgeInsets.only(top: 20, left: 20, right: 20), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ LocalText(context, "chart.date"), LocalText(context, "do.total_count") ], ), ), Column( children: getRowTotalCountWidget( chartModel.podoCount.getDOTotalCounts()), ) ], ), ], ), ), ), ); } List getRowTotalCountWidget(List data) { return data.map((d) { return Container( child: ExpansionTile( title: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text(dateFormatter.format(d.date), style: textStyle), Text(numberFormatter.format(d.totalCount), style: textStyle), ], ), children: [ SingleChildScrollView( scrollDirection: Axis.horizontal, child: MyDataTable( columnSpacing: 100, columns: [ MyDataColumn(label: LocalText(context, "do.count.status")), MyDataColumn(label: LocalText(context, "do.count")), ], rows: getStatusRow(d.detailCountsList), ), ), ], ), ); }).toList(); } List getStatusRow(List doList) { doList.sort((a, b) => a.status.compareTo(b.status)); return doList.map((d) { var r = MyDataRow( cells: [ MyDataCell( new Text(d.status, style: textStyle), ), MyDataCell( new Text( numberFormatter.format(d.count), style: textStyle, ), ), ], ); return r; }).toList(); } }