2019-07-16 14:12:16 +00:00
import ' package:flutter/material.dart ' ;
import ' package:local_spend/common/platform/platform_scaffold.dart ' ;
import ' package:shared_preferences/shared_preferences.dart ' ;
2019-08-19 14:02:02 +00:00
import ' package:local_spend/pages/customerGraphs.dart ' ;
import ' package:local_spend/pages/orgGraphs.dart ' ;
2019-07-16 14:12:16 +00:00
2019-08-21 13:53:52 +00:00
const url = " https://flutter.io/ " ;
2019-07-16 14:12:16 +00:00
const demonstration = false ;
class StatsPage extends StatefulWidget {
@ override
State < StatefulWidget > createState ( ) {
2019-08-27 10:00:57 +00:00
print ( " TODO: The 'stats' page should be loaded on login and cached rather than reloading on every opening of the page. " ) ;
print ( " Create new List<GraphData> in instantiated MyApp() and pass that or load it from this class' child with (graphs = super.graphList) or something. " ) ;
2019-07-16 14:12:16 +00:00
return new StatsPageState ( ) ;
}
}
class StatsPageState extends State < StatsPage > {
2019-08-19 14:02:02 +00:00
String userType = " - " ;
2019-07-18 11:05:09 +00:00
2019-07-16 14:12:16 +00:00
@ override
void initState ( ) {
super . initState ( ) ;
_saveCurrentRoute ( " /StatsPageState " ) ;
}
@ override
void dispose ( ) {
super . dispose ( ) ;
}
2019-08-21 13:53:52 +00:00
void _saveCurrentRoute ( String lastRoute ) async {
2019-07-16 14:12:16 +00:00
SharedPreferences preferences = await SharedPreferences . getInstance ( ) ;
await preferences . setString ( ' LastPageRoute ' , lastRoute ) ;
}
2019-08-19 14:02:02 +00:00
Future < String > _getUserType ( ) async {
SharedPreferences preferences = await SharedPreferences . getInstance ( ) ;
return await preferences . get ( ' LastUserType ' ) ;
}
2019-07-16 14:12:16 +00:00
@ override
Widget build ( BuildContext context ) {
2019-08-19 14:02:02 +00:00
if ( userType = = " - " ) {
_getUserType ( ) . then ( ( value ) {
print ( value ) ;
2019-08-21 13:53:52 +00:00
userType =
' ${ value [ 0 ] . toUpperCase ( ) } ${ value . substring ( 1 ) } ' ; // capitalises first letter
2019-08-12 15:03:00 +00:00
setState ( ( ) { } ) ;
} ) ;
}
2019-07-18 11:05:09 +00:00
2019-07-16 14:12:16 +00:00
return PlatformScaffold (
appBar: AppBar (
backgroundColor: Colors . blue [ 400 ] ,
2019-08-19 14:02:02 +00:00
title: Row (
crossAxisAlignment: CrossAxisAlignment . center ,
mainAxisAlignment: MainAxisAlignment . center ,
children: [
Text (
" Statistics " ,
style: TextStyle (
fontSize: 20 ,
color: Colors . white ,
2019-08-19 10:58:26 +00:00
) ,
2019-08-16 15:44:24 +00:00
) ,
2019-08-21 13:53:52 +00:00
Padding ( padding: EdgeInsets . symmetric ( horizontal: 4 ) ) ,
2019-08-19 14:02:02 +00:00
Text (
2019-08-19 14:32:54 +00:00
userType ,
2019-08-19 14:02:02 +00:00
style: TextStyle (
fontSize: 20 ,
color: Colors . white70 ,
2019-08-19 10:58:26 +00:00
) ,
2019-07-17 11:31:28 +00:00
) ,
2019-07-16 14:12:16 +00:00
] ,
) ,
2019-08-21 13:53:52 +00:00
centerTitle: true ,
iconTheme: IconThemeData ( color: Colors . black ) ,
) ,
body: Container (
2019-08-19 14:02:02 +00:00
padding: EdgeInsets . fromLTRB ( 0 , 0 , 0 , 0 ) ,
2019-08-21 13:53:52 +00:00
child: ( userType = = " - "
? null
: ( userType . toLowerCase ( ) = = " customer "
? CustomerGraphs ( )
: OrgGraphs ( ) ) ) ,
2019-07-16 14:12:16 +00:00
) ,
) ;
}
}