first step from IMEI

merge-requests/1/merge
Elham Rababah 6 years ago
parent 7227c71393
commit d080b5e1c4

@ -5,14 +5,16 @@ import 'package:http/http.dart' as http;
import '../models/user_model.dart'; import '../models/user_model.dart';
const LOGIN_URL = 'https://hmgwebservices.com/Services/Sentry.svc/REST/MemberLogIN_New';
const INSERT_DEVICE_IMEI = 'https://hmgwebservices.com/Services/Sentry.svc/REST/DoctorApplication_INSERTDeviceIMEI';
class AuthProvider with ChangeNotifier { class AuthProvider with ChangeNotifier {
Future<Map> login(UserModel userInfo) async { Future<Map> login(UserModel userInfo) async {
Map<String, String> requestHeaders = { Map<String, String> requestHeaders = {
'Content-type': 'application/json', 'Content-type': 'application/json',
'Accept': 'application/json', 'Accept': 'application/json',
}; };
const url = const url =LOGIN_URL;
'https://hmgwebservices.com/Services/Sentry.svc/REST/MemberLogIN_New';
try { try {
final response = await http.post(url, final response = await http.post(url,
headers: requestHeaders, headers: requestHeaders,
@ -31,4 +33,23 @@ class AuthProvider with ChangeNotifier {
print(error); print(error);
} }
} }
Future<Map> insertDeviceImei( imei) async {
Map<String, String> requestHeaders = {
'Content-type': 'application/json',
'Accept': 'application/json',
};
const url =INSERT_DEVICE_IMEI;
try {
final response = await http.post(url,
headers: requestHeaders,
body: json.encode(imei));
return Future.value(json.decode(response.body));
} catch (error) {
print(error);
}
}
} }

@ -1,5 +1,6 @@
import 'dart:async'; import 'dart:async';
import 'package:doctor_app_flutter/widgets/auth/known_user_login.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
@ -7,14 +8,14 @@ import '../../widgets/auth/auth_header.dart';
import '../../widgets/auth/login_form.dart'; import '../../widgets/auth/login_form.dart';
class Loginsreen extends StatelessWidget { class Loginsreen extends StatelessWidget {
// Future<SharedPreferences> pref = SharedPreferences.getInstance();
Future<SharedPreferences> _prefs = SharedPreferences.getInstance(); Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
int platformImei;
Future<void> _incrementCounter() async { Future<void> _incrementCounter() async {
final SharedPreferences prefs = await _prefs; final SharedPreferences prefs = await _prefs;
final int counter = (prefs.getInt('counter') ?? 0) + 1; final int counter = (prefs.getInt('counter') ?? 0) + 1;
var x = prefs.getInt('counter22222'); platformImei = prefs.getInt('platformImei');
// setState(() { // setState(() {
print(x); print('platformImei'+platformImei.toString());
prefs.setInt("counter", counter).then((bool success) { prefs.setInt("counter", counter).then((bool success) {
return counter; return counter;
// }); // });
@ -35,7 +36,7 @@ class Loginsreen extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
AuthHeader(), AuthHeader(),
LoginForm(), platformImei == null?LoginForm():KnownUserLogin(),
])), ])),
), ),
); );

@ -1,11 +1,11 @@
import '../../routes.dart';
import '../../widgets/patients/dynamic_elements.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:hexcolor/hexcolor.dart'; import 'package:hexcolor/hexcolor.dart';
import '../../lookups/patient_lookup.dart'; import '../../lookups/patient_lookup.dart';
import '../../models/patient_model.dart'; import '../../models/patient_model.dart';
import '../../routes.dart';
import '../../widgets/patients/dynamic_elements.dart';
class PatientSearchScreen extends StatefulWidget { class PatientSearchScreen extends StatefulWidget {
@override @override

@ -0,0 +1,12 @@
import 'package:flutter/material.dart';
class KnownUserLogin extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
child: Center(
child: Text(" welcome to Known User Login "),
),
);
}
}

@ -1,38 +1,55 @@
import '../../models/user_model.dart';
import '../../providers/auth_provider.dart';
import 'package:provider/provider.dart';
import '../../routes.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:hexcolor/hexcolor.dart'; import 'package:hexcolor/hexcolor.dart';
import 'package:imei_plugin/imei_plugin.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../../models/user_model.dart';
import '../../providers/auth_provider.dart';
import '../../routes.dart';
class LoginForm extends StatefulWidget {
class LoginForm extends StatelessWidget {
LoginForm({ LoginForm({
Key key, Key key,
}) : super(key: key); }) : super(key: key);
@override
_LoginFormState createState() => _LoginFormState();
}
class _LoginFormState extends State<LoginForm> {
final loginFormKey = GlobalKey<FormState>(); final loginFormKey = GlobalKey<FormState>();
String _platformImei = 'Unknown';
String uniqueId = "Unknown";
var userInfo = UserModel( var userInfo = UserModel(
UserID: '', UserID: '',
Password: '', Password: '',
ProjectID: 15, ProjectID: 15,
LanguageID: 2, LanguageID: 2,
IPAdress: "11.11.11.11", IPAdress: "11.11.11.11",
VersionID: 1.2, VersionID: 1.2,
Channel: 9, Channel: 9,
SessionID: "i1UJwCTSqt" SessionID: "i1UJwCTSqt");
);
@override
void initState() {
super.initState();
initPlatformState();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
AuthProvider authProv = Provider.of<AuthProvider>(context);
return LayoutBuilder(builder: (ctx, constraints) { return LayoutBuilder(builder: (ctx, constraints) {
var smallScreenSize = 660; var smallScreenSize = 660;
bool isSmallScreen = constraints.maxWidth <= smallScreenSize; bool isSmallScreen = constraints.maxWidth <= smallScreenSize;
return Form( return Form(
key: loginFormKey, key: loginFormKey,
child: Container( child: Container(
width: constraints.maxWidth * 0.9, width: constraints.maxWidth * 0.9,
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
@ -64,7 +81,7 @@ class LoginForm extends StatelessWidget {
} }
return null; return null;
}, },
onSaved: (value){ onSaved: (value) {
userInfo.UserID = value; userInfo.UserID = value;
}, },
), ),
@ -72,34 +89,35 @@ class LoginForm extends StatelessWidget {
height: 20, height: 20,
), ),
TextFormField( TextFormField(
obscureText: true, obscureText: true,
decoration: InputDecoration( decoration: InputDecoration(
prefixIcon: Image.asset('assets/images/password_icon.png'), prefixIcon:
hintText: 'Enter Password', Image.asset('assets/images/password_icon.png'),
hintStyle: TextStyle( hintText: 'Enter Password',
fontSize: hintStyle: TextStyle(
isSmallScreen ? 14 : constraints.maxWidth * 0.024), fontSize: isSmallScreen
enabledBorder: OutlineInputBorder( ? 14
borderRadius: BorderRadius.all(Radius.circular(20)), : constraints.maxWidth * 0.024),
borderSide: BorderSide(color: Hexcolor('#CCCCCC')), enabledBorder: OutlineInputBorder(
), borderRadius: BorderRadius.all(Radius.circular(20)),
focusedBorder: OutlineInputBorder( borderSide: BorderSide(color: Hexcolor('#CCCCCC')),
borderRadius: BorderRadius.all(Radius.circular(10.0)), ),
borderSide: focusedBorder: OutlineInputBorder(
BorderSide(color: Theme.of(context).primaryColor), borderRadius: BorderRadius.all(Radius.circular(10.0)),
) borderSide:
//BorderRadius.all(Radius.circular(20)); BorderSide(color: Theme.of(context).primaryColor),
), )
validator: (value) { //BorderRadius.all(Radius.circular(20));
if (value.isEmpty) { ),
return 'Please enter some text'; validator: (value) {
} if (value.isEmpty) {
return null; return 'Please enter some text';
}, }
onSaved: (value){ return null;
userInfo.Password = value; },
} onSaved: (value) {
), userInfo.Password = value;
}),
SizedBox( SizedBox(
height: 20, height: 20,
), ),
@ -152,14 +170,15 @@ class LoginForm extends StatelessWidget {
), ),
RaisedButton( RaisedButton(
onPressed: () { onPressed: () {
login(context); login(context, authProv);
}, },
textColor: Colors.white, textColor: Colors.white,
elevation: 0.0, elevation: 0.0,
padding: const EdgeInsets.all(0.0), padding: const EdgeInsets.all(0.0),
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10), borderRadius: BorderRadius.circular(10),
side: BorderSide(width: 0.5, color: Hexcolor('#CCCCCC'))), side:
BorderSide(width: 0.5, color: Hexcolor('#CCCCCC'))),
child: Container( child: Container(
padding: const EdgeInsets.all(10.0), padding: const EdgeInsets.all(10.0),
height: 50, height: 50,
@ -186,18 +205,83 @@ class LoginForm extends StatelessWidget {
}); });
} }
login(context) { login(context, AuthProvider authProv) {
AuthProvider authProv = Provider.of<AuthProvider>(context);
loginFormKey.currentState.validate(); loginFormKey.currentState.validate();
loginFormKey.currentState.save(); loginFormKey.currentState.save();
// if login succses
// set imei in shared preferanced
authProv.login(userInfo).then((res) { authProv.login(userInfo).then((res) {
print(res['MobileNumber']); print(res['MobileNumber']);
if (res['MessageStatus'] == 1) {
insertDeviceImei(res, authProv);
// call insert imei
// save imei on shared preferance
// handel errors
} else {
// handel error
}
print(_platformImei + '_platformImei0');
Navigator.of(context).pushNamed(HOME); Navigator.of(context).pushNamed(HOME);
}).catchError((err) { }).catchError((err) {
print('$err'); print('$err');
}); });
} }
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"
};
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.
Future<void> initPlatformState() async {
String platformImei;
String idunique;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
platformImei =
await ImeiPlugin.getImei(shouldShowRequestPermissionRationale: false);
idunique = await ImeiPlugin.getId();
} on PlatformException {
platformImei = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformImei = platformImei;
uniqueId = idunique;
});
}
Future<void> setSharedPref(key, value) async {
Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
final SharedPreferences prefs = await _prefs;
print(key);
print(value);
prefs.setInt(key, value).then((bool success) {
return;
});
}
} }

Loading…
Cancel
Save