2019-08-19 15:02:02 +01:00
import ' package:flutter/material.dart ' ;
import ' package:local_spend/common/apifunctions/get_graph_data.dart ' ;
2019-08-21 16:50:26 +01:00
import ' package:charts_flutter/flutter.dart ' as charts ;
2019-08-19 15:02:02 +01:00
class OrgGraphs extends StatefulWidget {
OrgGraphs ( { Key key } ) : super ( key: key ) ;
@ override
_OrgGraphsState createState ( ) {
return _OrgGraphsState ( ) ;
}
}
class _OrgGraphsState extends State < OrgGraphs > {
2019-08-21 16:50:26 +01:00
/// Organisations' graphs types: to fetch, POST to https://dev.localspend.co.uk/api/stats/[graph_type] as {"session_key":"[boop beep]"}
/// - organisations_all : organisation
/// - pies : organisation/pies
/// - snippets : organisation/snippets
/// - graphs : organisation/graphs
/// - {"graph":"customers_last_7_days","session_key":"[bleep]"}
/// - {"graph":"customers_last_30_days","session_key":"[blah]"}
/// - {"graph":"sales_last_7_days","session_key":"[bloop]"}
/// - {"graph":"sales_last_7_days","session_key":"[reee]"}
/// - {"graph":"purchases_last_7_days","session_key":"[yee]"}
/// - {"graph":"purchases_last_30_days","session_key":"[yah]"}
/// - {"graph":"purchases_all;","session_key":"[kappa]"} // I don't think this one works
///
/// HTTP POST request sample:
/// {"graph":"total_last_week","session_key":"blahblahblah"}
// OrganisationGraph customersLastWeek = new OrganisationGraph("graphs", graphsType: "customers_last_7_days");
2019-09-02 12:57:14 +01:00
OrganisationGraph customersLastMonth =
new OrganisationGraph ( " graphs " , graphsType: " customers_last_30_days " ) ;
OrganisationGraph salesLastMonth =
new OrganisationGraph ( " graphs " , graphsType: " sales_last_30_days " ) ;
OrganisationGraph purchasesLastMonth = new OrganisationGraph ( " graphs " ,
graphsType: " purchases_last_30_days " ) ; //purchases_last_30_days
2019-08-19 15:02:02 +01:00
@ override
void initState ( ) {
super . initState ( ) ;
}
@ override
void dispose ( ) {
super . dispose ( ) ;
}
@ override
Widget build ( BuildContext context ) {
2019-08-21 16:50:26 +01:00
// if (!customersLastWeek.loaded) {
// customersLastWeek.getGraphData().then((_) {
// setState(() {});
// });
// }
if ( ! customersLastMonth . loaded ) {
customersLastMonth . getGraphData ( ) . then ( ( _ ) {
setState ( ( ) { } ) ;
} ) ;
}
if ( ! salesLastMonth . loaded ) {
salesLastMonth . getGraphData ( ) . then ( ( _ ) {
setState ( ( ) { } ) ;
} ) ;
}
if ( ! purchasesLastMonth . loaded ) {
purchasesLastMonth . getGraphData ( ) . then ( ( _ ) {
setState ( ( ) { } ) ;
} ) ;
}
2019-08-19 15:02:02 +01:00
return ListView (
2019-08-21 16:50:26 +01:00
children: < Widget > [
// Container(
// padding: EdgeInsets.fromLTRB(0.0, 17, 0.0, 0.0),
// child: Text(
// "Last Week's Customers",
// textAlign: TextAlign.center,
// style: TextStyle(
// fontSize: 22.0,
// color: Colors.black,
// fontWeight: FontWeight.bold,
// ),
// ),
// ),
// Tooltip(
// message: "Graph of customers last week",
// child: Container(
// padding: EdgeInsets.symmetric(horizontal: 10),
// height: 200,
// child: customersLastWeek.graph != null
// ? new charts.TimeSeriesChart(customersLastWeek.graph)
// : Center(
// child: Text(
// "Loading graph...")), //List<Series<dynamic, DateTime>>
// ),
// ),
Container (
padding: EdgeInsets . fromLTRB ( 0.0 , 17 , 0.0 , 0.0 ) ,
child: Text (
" This Month's Customers " ,
textAlign: TextAlign . center ,
style: TextStyle (
fontSize: 22.0 ,
color: Colors . black ,
fontWeight: FontWeight . bold ,
) ,
) ,
) ,
Tooltip (
message: " Customers this month " , // this needs to be better
child: Container (
padding: EdgeInsets . symmetric ( horizontal: 10 ) ,
height: 200 ,
child: customersLastMonth . graph ! = null
? new charts . TimeSeriesChart ( customersLastMonth . graph )
: Center (
2019-09-02 12:57:14 +01:00
child:
CircularProgressIndicator ( ) ) , //List<Series<dynamic, DateTime>>
2019-08-21 16:50:26 +01:00
) ,
) ,
Container (
padding: EdgeInsets . fromLTRB ( 0.0 , 17 , 0.0 , 0.0 ) ,
child: Text (
" This Month's Revenue " ,
textAlign: TextAlign . center ,
style: TextStyle (
fontSize: 22.0 ,
color: Colors . black ,
fontWeight: FontWeight . bold ,
) ,
) ,
) ,
Tooltip (
message: " Revenue from sales this month " ,
child: Container (
padding: EdgeInsets . symmetric ( horizontal: 10 ) ,
height: 200 ,
child: salesLastMonth . graph ! = null
? new charts . TimeSeriesChart ( salesLastMonth . graph )
: Center (
2019-09-02 12:57:14 +01:00
child: CircularProgressIndicator (
valueColor: new AlwaysStoppedAnimation < Color > ( Colors . green ) ,
) ) , //List<Series<dynamic, DateTime>>
2019-08-21 16:50:26 +01:00
) ,
) ,
Container (
padding: EdgeInsets . fromLTRB ( 0.0 , 17 , 0.0 , 0.0 ) ,
child: Text (
" This Month's Sales " ,
textAlign: TextAlign . center ,
style: TextStyle (
fontSize: 22.0 ,
color: Colors . black ,
fontWeight: FontWeight . bold ,
) ,
) ,
) ,
Tooltip (
message: " Number of sales this month " ,
child: Container (
padding: EdgeInsets . symmetric ( horizontal: 10 ) ,
height: 200 ,
child: purchasesLastMonth . graph ! = null
? new charts . TimeSeriesChart ( purchasesLastMonth . graph )
: Center (
2019-09-02 12:57:14 +01:00
child: CircularProgressIndicator (
2019-08-21 16:59:08 +01:00
valueColor: new AlwaysStoppedAnimation < Color > ( Colors . red ) ,
2019-09-02 12:57:14 +01:00
) ) , //List<Series<dynamic, DateTime>>
2019-08-21 16:50:26 +01:00
) ,
) ,
] ,
2019-08-19 15:02:02 +01:00
) ;
}
2019-08-21 14:53:52 +01:00
}