2019-07-16 15:12:16 +01: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 15:02:02 +01:00
import ' package:local_spend/pages/customerGraphs.dart ' ;
import ' package:local_spend/pages/orgGraphs.dart ' ;
2019-07-16 15:12:16 +01:00
const URL = " https://flutter.io/ " ;
const demonstration = false ;
class StatsPage extends StatefulWidget {
@ override
State < StatefulWidget > createState ( ) {
return new StatsPageState ( ) ;
}
}
class StatsPageState extends State < StatsPage > {
2019-08-19 15:02:02 +01:00
String userType = " - " ;
2019-07-18 12:05:09 +01:00
2019-07-16 15:12:16 +01:00
@ override
void initState ( ) {
super . initState ( ) ;
_saveCurrentRoute ( " /StatsPageState " ) ;
}
@ override
void dispose ( ) {
super . dispose ( ) ;
}
_saveCurrentRoute ( String lastRoute ) async {
SharedPreferences preferences = await SharedPreferences . getInstance ( ) ;
await preferences . setString ( ' LastPageRoute ' , lastRoute ) ;
}
2019-08-19 15:02:02 +01:00
Future < String > _getUserType ( ) async {
SharedPreferences preferences = await SharedPreferences . getInstance ( ) ;
return await preferences . get ( ' LastUserType ' ) ;
}
2019-07-16 15:12:16 +01:00
@ override
Widget build ( BuildContext context ) {
2019-08-19 15:02:02 +01:00
if ( userType = = " - " ) {
_getUserType ( ) . then ( ( value ) {
print ( value ) ;
userType = ' ${ value [ 0 ] . toUpperCase ( ) } ${ value . substring ( 1 ) } ' ; // capitalises first letter
2019-08-12 16:03:00 +01:00
setState ( ( ) { } ) ;
} ) ;
}
2019-07-18 12:05:09 +01:00
2019-07-16 15:12:16 +01:00
return PlatformScaffold (
appBar: AppBar (
backgroundColor: Colors . blue [ 400 ] ,
2019-08-19 15:02:02 +01:00
title: Row (
crossAxisAlignment: CrossAxisAlignment . center ,
mainAxisAlignment: MainAxisAlignment . center ,
children: [
Text (
" Statistics " ,
style: TextStyle (
fontSize: 20 ,
color: Colors . white ,
2019-08-19 11:58:26 +01:00
) ,
2019-08-16 16:44:24 +01:00
) ,
2019-08-19 15:02:02 +01:00
Padding (
2019-08-19 15:23:58 +01:00
padding: EdgeInsets . symmetric ( horizontal: 7 )
2019-08-16 16:44:24 +01:00
) ,
2019-08-19 15:02:02 +01:00
Text (
" User type: " + userType ,
style: TextStyle (
fontSize: 20 ,
color: Colors . white70 ,
2019-08-19 11:58:26 +01:00
) ,
2019-07-17 12:31:28 +01:00
) ,
2019-07-16 15:12:16 +01:00
] ,
) ,
2019-08-19 15:02:02 +01:00
centerTitle: true ,
iconTheme: IconThemeData ( color: Colors . black ) ,
) ,
body : Container (
padding: EdgeInsets . fromLTRB ( 0 , 0 , 0 , 0 ) ,
child: ( userType = = " - " ? null : ( userType . toLowerCase ( ) = = " customer " ? CustomerGraphs ( ) : OrgGraphs ( ) ) ) ,
2019-07-16 15:12:16 +01:00
) ,
) ;
}
}