2019-08-19 15:02:02 +01:00
import ' package:flutter/material.dart ' ;
import ' package:local_spend/common/apifunctions/get_graph_data.dart ' ;
import ' package:charts_flutter/flutter.dart ' as charts ;
class CustomerGraphs extends StatefulWidget {
CustomerGraphs ( { Key key } ) : super ( key: key ) ;
@ override
_CustomerGraphsState createState ( ) {
return _CustomerGraphsState ( ) ;
}
}
class _CustomerGraphsState extends State < CustomerGraphs > {
GraphData totalLastWeekGraph = new GraphData ( " total_last_week " ) ;
GraphData avgSpendLastWeekGraph = new GraphData ( " avg_spend_last_week " ) ;
GraphData totalLastMonthGraph = new GraphData ( " total_last_month " ) ;
GraphData avgSpendLastMonth = new GraphData ( " avg_spend_last_month " ) ;
@ override
void initState ( ) {
super . initState ( ) ;
}
@ override
void dispose ( ) {
super . dispose ( ) ;
}
@ override
Widget build ( BuildContext context ) {
// Initializing graphs:
if ( ! totalLastWeekGraph . loaded ) {
totalLastWeekGraph . setGraphData ( ) . then ( ( _ ) {
setState ( ( ) { } ) ;
} ) ;
}
if ( ! avgSpendLastWeekGraph . loaded ) {
avgSpendLastWeekGraph . setGraphData ( ) . then ( ( _ ) {
setState ( ( ) { } ) ;
} ) ;
}
if ( ! totalLastMonthGraph . loaded ) {
totalLastMonthGraph . setGraphData ( ) . then ( ( _ ) {
setState ( ( ) { } ) ;
} ) ;
}
if ( ! avgSpendLastMonth . loaded ) {
avgSpendLastMonth . setGraphData ( ) . then ( ( _ ) {
setState ( ( ) { } ) ;
} ) ;
}
return ListView (
children: < Widget > [
Container (
2019-08-21 14:53:52 +01:00
padding: EdgeInsets . fromLTRB ( 0.0 , 17 , 0.0 , 0.0 ) ,
child: Text (
2019-08-19 15:02:02 +01:00
" Last Week's Total Spend " ,
textAlign: TextAlign . center ,
style: TextStyle (
fontSize: 22.0 ,
color: Colors . black ,
fontWeight: FontWeight . bold ,
) ,
) ,
) ,
Tooltip (
message: " Graph of total spend last week " ,
2019-08-21 14:53:52 +01:00
child: Container (
2019-08-19 15:02:02 +01:00
padding: EdgeInsets . symmetric ( horizontal: 10 ) ,
height: 200 ,
2019-08-21 14:53:52 +01:00
child: totalLastWeekGraph . graph ! = null
? new charts . TimeSeriesChart ( totalLastWeekGraph . graph )
: Center (
2019-09-02 12:57:14 +01:00
child: CircularProgressIndicator (
valueColor:
new AlwaysStoppedAnimation < Color > ( Colors . orange ) ,
) ) , //List<Series<dynamic, DateTime>>es<dynamic, DateTime>>
2019-08-19 15:02:02 +01:00
) ,
) ,
Container (
2019-08-21 14:53:52 +01:00
padding: EdgeInsets . fromLTRB ( 0.0 , 17 , 0.0 , 0.0 ) ,
child: Text (
2019-08-19 15:02:02 +01:00
" Last Week's Average Spend " ,
textAlign: TextAlign . center ,
style: TextStyle (
fontSize: 22.0 ,
color: Colors . black ,
fontWeight: FontWeight . bold ,
) ,
) ,
) ,
Tooltip (
message: " Graph of average spend last week " ,
2019-08-21 14:53:52 +01:00
child: Container (
2019-08-19 15:02:02 +01:00
padding: EdgeInsets . symmetric ( horizontal: 10 ) ,
height: 200 ,
2019-08-21 14:53:52 +01:00
child: avgSpendLastWeekGraph . graph ! = null
? new charts . TimeSeriesChart ( avgSpendLastWeekGraph . graph )
: Center (
2019-08-21 16:59:08 +01:00
child: CircularProgressIndicator (
2019-09-02 12:57:14 +01:00
valueColor: new AlwaysStoppedAnimation < Color > ( Colors . blue ) ,
) ) , //List<Series<dynamic, DateTime>>es<dynamic, DateTime>>
2019-08-19 15:02:02 +01:00
) ,
) ,
Container (
2019-08-21 14:53:52 +01:00
padding: EdgeInsets . fromLTRB ( 0.0 , 17 , 0.0 , 0.0 ) ,
child: Text (
2019-08-19 15:02:02 +01:00
" Last Month's Total Spend " ,
textAlign: TextAlign . center ,
style: TextStyle (
fontSize: 22.0 ,
color: Colors . black ,
fontWeight: FontWeight . bold ,
) ,
) ,
) ,
Tooltip (
message: " Graph of total spend last month " ,
2019-08-21 14:53:52 +01:00
child: Container (
2019-08-19 15:02:02 +01:00
padding: EdgeInsets . symmetric ( horizontal: 10 ) ,
height: 200 ,
2019-08-21 14:53:52 +01:00
child: totalLastMonthGraph . graph ! = null
? new charts . TimeSeriesChart ( totalLastMonthGraph . graph )
: Center (
2019-09-02 12:57:14 +01:00
child: CircularProgressIndicator (
valueColor: new AlwaysStoppedAnimation < Color > ( Colors . green ) ,
) ) , //List<Series<dynamic, DateTime>>es<dynamic, DateTime>>
2019-08-19 15:02:02 +01:00
) ,
) ,
Container (
2019-08-21 14:53:52 +01:00
padding: EdgeInsets . fromLTRB ( 0.0 , 17 , 0.0 , 0.0 ) ,
child: Text (
2019-08-19 15:02:02 +01:00
" Last Month's Average Spend " ,
textAlign: TextAlign . center ,
style: TextStyle (
fontSize: 22.0 ,
color: Colors . black ,
fontWeight: FontWeight . bold ,
) ,
) ,
) ,
Tooltip (
message: " Graph of average spend last month " ,
2019-08-21 14:53:52 +01:00
child: Container (
2019-08-19 15:02:02 +01:00
padding: EdgeInsets . symmetric ( horizontal: 10 ) ,
height: 200 ,
2019-08-21 14:53:52 +01:00
child: avgSpendLastMonth . graph ! = null
? new charts . TimeSeriesChart ( avgSpendLastMonth . 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>>es<dynamic, DateTime>>
2019-08-19 15:02:02 +01:00
) ,
) ,
] ,
) ;
}
2019-08-21 14:53:52 +01:00
}