first step form real login and calling Api

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

@ -1,3 +1,4 @@
import 'package:doctor_app_flutter/providers/auth_provider.dart';
import 'package:doctor_app_flutter/providers/patients_provider.dart'; import 'package:doctor_app_flutter/providers/patients_provider.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:hexcolor/hexcolor.dart'; import 'package:hexcolor/hexcolor.dart';
@ -12,6 +13,8 @@ class MyApp extends StatelessWidget {
return MultiProvider( return MultiProvider(
providers: [ providers: [
ChangeNotifierProvider.value(value: PatientsProvider()), ChangeNotifierProvider.value(value: PatientsProvider()),
ChangeNotifierProvider.value(value: AuthProvider()),
], ],
child: MaterialApp( child: MaterialApp(
title: 'Flutter Demo', title: 'Flutter Demo',

@ -0,0 +1,20 @@
class UserModel {
String UserID;
String Password;
int ProjectID;
int LanguageID;
String IPAdress;
double VersionID;
int Channel;
String SessionID;
UserModel(
{this.UserID,
this.Password,
this.ProjectID,
this.LanguageID,
this.IPAdress,
this.VersionID,
this.Channel,
this.SessionID});
}

@ -0,0 +1,34 @@
import 'dart:convert';
import 'package:flutter/cupertino.dart';
import 'package:http/http.dart' as http;
import '../models/user_model.dart';
class AuthProvider with ChangeNotifier {
Future<Map> login(UserModel userInfo) async {
Map<String, String> requestHeaders = {
'Content-type': 'application/json',
'Accept': 'application/json',
};
const url =
'https://hmgwebservices.com/Services/Sentry.svc/REST/MemberLogIN_New';
try {
final response = await http.post(url,
headers: requestHeaders,
body: json.encode({
"UserID": userInfo.UserID,
"Password": userInfo.Password,
"ProjectID": userInfo.ProjectID,
"LanguageID": userInfo.LanguageID,
"IPAdress": userInfo.IPAdress,
"VersionID": userInfo.VersionID,
"Channel": userInfo.Channel,
"SessionID": userInfo.SessionID
}));
return Future.value(json.decode(response.body));
} catch (error) {
print(error);
}
}
}

@ -1,9 +1,8 @@
import 'dart:io'; import 'dart:convert';
import 'package:doctor_app_flutter/models/patient_model.dart'; import 'package:doctor_app_flutter/models/patient_model.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'dart:convert';
class PatientsProvider with ChangeNotifier { class PatientsProvider with ChangeNotifier {
Future<Map> getPatientList(PatientModel patient, patientType) async { Future<Map> getPatientList(PatientModel patient, patientType) async {
@ -30,7 +29,7 @@ class PatientsProvider with ChangeNotifier {
"To": patient.To, "To": patient.To,
"LanguageID": patient.LanguageID, "LanguageID": patient.LanguageID,
"stamp": patient.stamp, "stamp": patient.stamp,
"IPAdress":patient.IPAdress, "IPAdress": patient.IPAdress,
"VersionID": patient.VersionID, "VersionID": patient.VersionID,
"Channel": patient.Channel, "Channel": patient.Channel,
"TokenID": patient.TokenID, "TokenID": patient.TokenID,

@ -1,15 +1,14 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import '../../widgets/auth/auth_header.dart'; import '../../widgets/auth/auth_header.dart';
import '../../widgets/auth/login_form.dart'; import '../../widgets/auth/login_form.dart';
import 'package:flutter/material.dart';
import 'dart:async';
class Loginsreen extends StatelessWidget { class Loginsreen extends StatelessWidget {
// Future<SharedPreferences> pref = SharedPreferences.getInstance(); // Future<SharedPreferences> pref = SharedPreferences.getInstance();
Future<SharedPreferences> _prefs = SharedPreferences.getInstance(); Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
// final SharedPreferences prefs = await _prefs;
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;
@ -23,6 +22,7 @@ class Loginsreen extends StatelessWidget {
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// prefs.setInt("counter", 1); // prefs.setInt("counter", 1);
_incrementCounter(); _incrementCounter();
return Scaffold( return Scaffold(

@ -1,21 +1,38 @@
import '../../models/user_model.dart';
import '../../providers/auth_provider.dart';
import 'package:provider/provider.dart';
import '../../routes.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:hexcolor/hexcolor.dart'; import 'package:hexcolor/hexcolor.dart';
class LoginForm extends StatelessWidget { class LoginForm extends StatelessWidget {
const LoginForm({ LoginForm({
Key key, Key key,
}) : super(key: key); }) : super(key: key);
final loginFormKey = GlobalKey<FormState>();
var userInfo = UserModel(
UserID: '',
Password: '',
ProjectID: 15,
LanguageID: 2,
IPAdress: "11.11.11.11",
VersionID: 1.2,
Channel: 9,
SessionID: "i1UJwCTSqt"
);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext 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 Container( return Form(
key: loginFormKey,
child: Container(
width: constraints.maxWidth * 0.9, width: constraints.maxWidth * 0.9,
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
@ -27,7 +44,9 @@ class LoginForm extends StatelessWidget {
decoration: InputDecoration( decoration: InputDecoration(
prefixIcon: Image.asset('assets/images/user_id_icon.png'), prefixIcon: Image.asset('assets/images/user_id_icon.png'),
hintText: 'Enter ID', hintText: 'Enter ID',
hintStyle: TextStyle(fontSize:isSmallScreen?14:constraints.maxWidth*0.024) , hintStyle: TextStyle(
fontSize:
isSmallScreen ? 14 : constraints.maxWidth * 0.024),
enabledBorder: OutlineInputBorder( enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(20)), borderRadius: BorderRadius.all(Radius.circular(20)),
borderSide: BorderSide(color: Hexcolor('#CCCCCC')), borderSide: BorderSide(color: Hexcolor('#CCCCCC')),
@ -45,6 +64,9 @@ class LoginForm extends StatelessWidget {
} }
return null; return null;
}, },
onSaved: (value){
userInfo.UserID = value;
},
), ),
SizedBox( SizedBox(
height: 20, height: 20,
@ -54,7 +76,9 @@ class LoginForm extends StatelessWidget {
decoration: InputDecoration( decoration: InputDecoration(
prefixIcon: Image.asset('assets/images/password_icon.png'), prefixIcon: Image.asset('assets/images/password_icon.png'),
hintText: 'Enter Password', hintText: 'Enter Password',
hintStyle: TextStyle(fontSize:isSmallScreen?14:constraints.maxWidth*0.024) , hintStyle: TextStyle(
fontSize:
isSmallScreen ? 14 : constraints.maxWidth * 0.024),
enabledBorder: OutlineInputBorder( enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(20)), borderRadius: BorderRadius.all(Radius.circular(20)),
borderSide: BorderSide(color: Hexcolor('#CCCCCC')), borderSide: BorderSide(color: Hexcolor('#CCCCCC')),
@ -72,6 +96,9 @@ class LoginForm extends StatelessWidget {
} }
return null; return null;
}, },
onSaved: (value){
userInfo.Password = value;
}
), ),
SizedBox( SizedBox(
height: 20, height: 20,
@ -80,7 +107,9 @@ class LoginForm extends StatelessWidget {
decoration: InputDecoration( decoration: InputDecoration(
prefixIcon: Image.asset('assets/images/hospital_icon.png'), prefixIcon: Image.asset('assets/images/hospital_icon.png'),
hintText: 'Select Project', hintText: 'Select Project',
hintStyle: TextStyle(fontSize:isSmallScreen?14:constraints.maxWidth*0.024) , hintStyle: TextStyle(
fontSize:
isSmallScreen ? 14 : constraints.maxWidth * 0.024),
enabledBorder: OutlineInputBorder( enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(20)), borderRadius: BorderRadius.all(Radius.circular(20)),
borderSide: BorderSide(color: Hexcolor('#CCCCCC')), borderSide: BorderSide(color: Hexcolor('#CCCCCC')),
@ -113,13 +142,17 @@ class LoginForm extends StatelessWidget {
value: true, value: true,
activeColor: Theme.of(context).primaryColor, activeColor: Theme.of(context).primaryColor,
onChanged: (bool newValue) {}), onChanged: (bool newValue) {}),
Text("Remember me", style: TextStyle(fontSize:isSmallScreen?18:constraints.maxWidth*0.018)), Text("Remember me",
style: TextStyle(
fontSize: isSmallScreen
? 18
: constraints.maxWidth * 0.018)),
], ],
), ),
), ),
RaisedButton( RaisedButton(
onPressed: () { onPressed: () {
Navigator.of(context).pushNamed(HOME); login(context);
}, },
textColor: Colors.white, textColor: Colors.white,
elevation: 0.0, elevation: 0.0,
@ -134,7 +167,11 @@ class LoginForm extends StatelessWidget {
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[ children: <Widget>[
Text('LOG IN', style: TextStyle(fontSize:isSmallScreen?20:constraints.maxWidth*0.020)), Text('LOG IN',
style: TextStyle(
fontSize: isSmallScreen
? 20
: constraints.maxWidth * 0.020)),
Image.asset('assets/images/login_btn_arrow_icon.png') Image.asset('assets/images/login_btn_arrow_icon.png')
], ],
), ),
@ -144,7 +181,23 @@ class LoginForm extends StatelessWidget {
), ),
], ],
), ),
),
); );
}); });
} }
login(context) {
AuthProvider authProv = Provider.of<AuthProvider>(context);
loginFormKey.currentState.validate();
loginFormKey.currentState.save();
// if login succses
// set imei in shared preferanced
authProv.login(userInfo).then((res) {
print(res['MobileNumber']);
Navigator.of(context).pushNamed(HOME);
}).catchError((err) {
print('$err');
});
}
} }

@ -275,6 +275,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.4" version: "2.1.4"
imei_plugin:
dependency: "direct main"
description:
name: imei_plugin
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.6"
intl: intl:
dependency: "direct main" dependency: "direct main"
description: description:

@ -26,6 +26,8 @@ dependencies:
provider: ^3.0.0 provider: ^3.0.0
i18n: any i18n: any
shared_preferences: ^0.5.6+3 shared_preferences: ^0.5.6+3
imei_plugin: ^1.1.6
# The following adds the Cupertino Icons font to your application. # The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons. # Use with the CupertinoIcons class for iOS style icons.

Loading…
Cancel
Save