diff --git a/lib/screens/auth/login_screen.dart b/lib/screens/auth/login_screen.dart index 5859e1a1..eab926ce 100644 --- a/lib/screens/auth/login_screen.dart +++ b/lib/screens/auth/login_screen.dart @@ -7,39 +7,70 @@ import 'package:shared_preferences/shared_preferences.dart'; import '../../widgets/auth/auth_header.dart'; import '../../widgets/auth/login_form.dart'; -class Loginsreen extends StatelessWidget { +class Loginsreen extends StatefulWidget { + @override + _LoginsreenState createState() => _LoginsreenState(); +} + +class _LoginsreenState extends State { Future _prefs = SharedPreferences.getInstance(); - int platformImei; + + String platformImei; + + Future platformImeiText; + Future _incrementCounter() async { final SharedPreferences prefs = await _prefs; final int counter = (prefs.getInt('counter') ?? 0) + 1; - platformImei = prefs.getInt('platformImei'); + platformImei = prefs.getString('platformImei'); // setState(() { - print('platformImei'+platformImei.toString()); - prefs.setInt("counter", counter).then((bool success) { - return counter; + print(platformImei); + prefs.setInt("counter", counter).then((bool success) { + return counter; // }); }); } + @override - Widget build(BuildContext context) { + void initState() { + super.initState(); + platformImeiText = _prefs.then((SharedPreferences prefs) { + return (prefs.getString('platformImei')); + }); + } + @override + Widget build(BuildContext context) { // prefs.setInt("counter", 1); _incrementCounter(); return Scaffold( backgroundColor: Colors.white, body: SingleChildScrollView( - child: Container( - margin: EdgeInsetsDirectional.fromSTEB(30, 0, 0, 0), - alignment: Alignment.topLeft, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - AuthHeader(), - platformImei == null?LoginForm():KnownUserLogin(), - ])), + child: FutureBuilder( + future: platformImeiText, + builder: (BuildContext context, AsyncSnapshot snapshot) { + switch (snapshot.connectionState) { + case ConnectionState.waiting: + return const CircularProgressIndicator(); + default: + if (snapshot.hasError) { + return Text('Error: ${snapshot.error}'); + } else { + return Container( + margin: EdgeInsetsDirectional.fromSTEB(30, 0, 0, 0), + alignment: Alignment.topLeft, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + AuthHeader(), + (platformImei == null) + ? LoginForm() + : KnownUserLogin(), + ])); + } + } + }), ), ); } } - diff --git a/lib/widgets/auth/login_form.dart b/lib/widgets/auth/login_form.dart index 8892cf5a..326e2b3c 100644 --- a/lib/widgets/auth/login_form.dart +++ b/lib/widgets/auth/login_form.dart @@ -151,10 +151,9 @@ class _LoginFormState extends State { // return null; // }, // ), - // + // Container( decoration: BoxDecoration( - borderRadius: BorderRadius.all(Radius.circular(10.0)), // border: Border.all(color: Theme.of(context).primaryColor), ), @@ -179,7 +178,7 @@ class _LoginFormState extends State { }, ), ), - + SizedBox( height: 20, ), @@ -258,31 +257,33 @@ class _LoginFormState extends State { } insertDeviceImei(res, AuthProvider authProv) { - var imeiInfo = { - "IMEI": _platformImei.toString(), - "LogInType": 1, - "DoctorID": res['DoctorID'], - "DoctorName": "Test User", - "Gender": 1, - "ClinicID": 3, - "ProjectID": 15, - "DoctorTitle": "Mr.", - "ClinicName": "MED", - "ProjectName": "", - "DoctorImageURL": "UNKNOWN", - "LogInTokenID": res['LogInTokenID'], - "VersionID": 1.2 - }; - authProv.insertDeviceImei(imeiInfo).then((res) { - if (res['MessageStatus'] == 1) { - setSharedPref('platformImei', _platformImei); - // save imei on shared preferance - } else { - // handel error - } - }).catchError((err) { - print(err); - }); + if (_platformImei != 'Unknown') { + var imeiInfo = { + "IMEI": _platformImei, + "LogInType": 1, + "DoctorID": res['DoctorID'], + "DoctorName": "Test User", + "Gender": 1, + "ClinicID": 3, + "ProjectID": 15, + "DoctorTitle": "Mr.", + "ClinicName": "MED", + "ProjectName": "", + "DoctorImageURL": "UNKNOWN", + "LogInTokenID": res['LogInTokenID'], + "VersionID": 1.2 + }; + authProv.insertDeviceImei(imeiInfo).then((res) { + if (res['MessageStatus'] == 1) { + setSharedPref('platformImei', _platformImei); + // save imei on shared preferance + } else { + // handel error + } + }).catchError((err) { + print(err); + }); + } } // Platform messages are asynchronous, so we initialize in an async method. @@ -313,8 +314,10 @@ class _LoginFormState extends State { Future _prefs = SharedPreferences.getInstance(); final SharedPreferences prefs = await _prefs; - prefs.setInt(key, value).then((bool success) { - return; + prefs.setString(key, value).then((bool success) { + print('EEEEEEEEEEee'); + print(prefs.getString('platformImei')); + return value; }); }