add structure
This commit is contained in:
119
lib/charts/bar_chart.dart
Normal file
119
lib/charts/bar_chart.dart
Normal file
@@ -0,0 +1,119 @@
|
||||
import 'package:charts_flutter/flutter.dart' as charts;
|
||||
import 'package:charts_flutter/flutter.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:fcs/charts/qtyby_customer_table.dart';
|
||||
import 'package:fcs/model/chart_model.dart';
|
||||
import 'package:fcs/model/product_model.dart';
|
||||
import 'package:fcs/theme/theme.dart';
|
||||
import 'package:fcs/vo/po.dart';
|
||||
import 'package:fcs/widget/local_text.dart';
|
||||
|
||||
class BarChart extends StatefulWidget {
|
||||
@override
|
||||
_BarChartState createState() => _BarChartState();
|
||||
}
|
||||
|
||||
class _BarChartState extends State<BarChart> {
|
||||
static final numberFormatter = new NumberFormat("#,###");
|
||||
List<POChartData> chartSummary = new List();
|
||||
List<charts.Series<POChartData, String>> series;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
var chartModel = Provider.of<ChartModel>(context, listen: false);
|
||||
this.chartSummary = chartModel.chartSummary;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var productModel = Provider.of<ProductModel>(context);
|
||||
if (this.chartSummary.isNotEmpty) {
|
||||
this.chartSummary.forEach((s) {
|
||||
productModel.products.forEach((p) {
|
||||
if (p.id == s.productID) {
|
||||
s.displayOrder = p.displayOrder;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
this.chartSummary
|
||||
.sort((s1, s2) => s1.displayOrder.compareTo(s2.displayOrder));
|
||||
}
|
||||
List<charts.Series<POChartData, String>> series = [
|
||||
charts.Series(
|
||||
id: "Subscribers",
|
||||
data: this.chartSummary,
|
||||
domainFn: (POChartData series, _) => series.productName,
|
||||
measureFn: (POChartData series, _) => series.balanceQty,
|
||||
colorFn: (POChartData series, _) =>
|
||||
charts.ColorUtil.fromDartColor(series.getColor),
|
||||
labelAccessorFn: (POChartData series, _) =>
|
||||
'${numberFormatter.format(series.balanceQty)}'),
|
||||
];
|
||||
|
||||
return Container(
|
||||
height: 200,
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: <Widget>[
|
||||
LocalText(context, 'product.balance_qty',
|
||||
color: primaryColor, fontSize: 16),
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
Icons.refresh,
|
||||
color: primaryColor,
|
||||
),
|
||||
onPressed: () {
|
||||
_load();
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
Expanded(
|
||||
child: charts.BarChart(
|
||||
series,
|
||||
animate: true,
|
||||
vertical: false,
|
||||
defaultRenderer: new charts.BarRendererConfig(
|
||||
barRendererDecorator: new charts.BarLabelDecorator<String>(
|
||||
labelPosition: charts.BarLabelPosition.auto,
|
||||
),
|
||||
),
|
||||
selectionModels: [
|
||||
SelectionModelConfig(changedListener: (SelectionModel model) {
|
||||
final selectedDatum = model.selectedDatum;
|
||||
if (selectedDatum.isNotEmpty) {
|
||||
selectedDatum.forEach((charts.SeriesDatum datumPair) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => QtyByCustomerTable(
|
||||
poChartData: datumPair.datum,
|
||||
)),
|
||||
);
|
||||
});
|
||||
}
|
||||
})
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _load() async {
|
||||
var chartModel = Provider.of<ChartModel>(context);
|
||||
var _s = await chartModel.loadSummary();
|
||||
setState(() {
|
||||
this.chartSummary = _s ?? [];
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user