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,150 +1,203 @@
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(
width: constraints.maxWidth * 0.9, key: loginFormKey,
child: Column( child: Container(
crossAxisAlignment: CrossAxisAlignment.start, width: constraints.maxWidth * 0.9,
children: <Widget>[ child: Column(
SizedBox( crossAxisAlignment: CrossAxisAlignment.start,
height: 20, children: <Widget>[
), SizedBox(
TextFormField( height: 20,
decoration: InputDecoration( ),
prefixIcon: Image.asset('assets/images/user_id_icon.png'), TextFormField(
hintText: 'Enter ID', decoration: InputDecoration(
hintStyle: TextStyle(fontSize:isSmallScreen?14:constraints.maxWidth*0.024) , prefixIcon: Image.asset('assets/images/user_id_icon.png'),
enabledBorder: OutlineInputBorder( hintText: 'Enter ID',
borderRadius: BorderRadius.all(Radius.circular(20)), hintStyle: TextStyle(
borderSide: BorderSide(color: Hexcolor('#CCCCCC')), fontSize:
), isSmallScreen ? 14 : constraints.maxWidth * 0.024),
focusedBorder: OutlineInputBorder( enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(10.0)), borderRadius: BorderRadius.all(Radius.circular(20)),
borderSide: borderSide: BorderSide(color: Hexcolor('#CCCCCC')),
BorderSide(color: Theme.of(context).primaryColor), ),
) focusedBorder: OutlineInputBorder(
//BorderRadius.all(Radius.circular(20)); borderRadius: BorderRadius.all(Radius.circular(10.0)),
), borderSide:
validator: (value) { BorderSide(color: Theme.of(context).primaryColor),
if (value.isEmpty) { )
return 'Please enter some text'; //BorderRadius.all(Radius.circular(20));
} ),
return null; validator: (value) {
}, if (value.isEmpty) {
), return 'Please enter some text';
SizedBox( }
height: 20, return null;
), },
TextFormField( onSaved: (value){
obscureText: true, userInfo.UserID = value;
decoration: InputDecoration( },
prefixIcon: Image.asset('assets/images/password_icon.png'), ),
hintText: 'Enter Password', SizedBox(
hintStyle: TextStyle(fontSize:isSmallScreen?14:constraints.maxWidth*0.024) , height: 20,
enabledBorder: OutlineInputBorder( ),
borderRadius: BorderRadius.all(Radius.circular(20)), TextFormField(
borderSide: BorderSide(color: Hexcolor('#CCCCCC')), obscureText: true,
), decoration: InputDecoration(
focusedBorder: OutlineInputBorder( prefixIcon: Image.asset('assets/images/password_icon.png'),
borderRadius: BorderRadius.all(Radius.circular(10.0)), hintText: 'Enter Password',
borderSide: hintStyle: TextStyle(
BorderSide(color: Theme.of(context).primaryColor), fontSize:
) isSmallScreen ? 14 : constraints.maxWidth * 0.024),
//BorderRadius.all(Radius.circular(20)); enabledBorder: OutlineInputBorder(
), borderRadius: BorderRadius.all(Radius.circular(20)),
validator: (value) { borderSide: BorderSide(color: Hexcolor('#CCCCCC')),
if (value.isEmpty) { ),
return 'Please enter some text'; focusedBorder: OutlineInputBorder(
} borderRadius: BorderRadius.all(Radius.circular(10.0)),
return null; borderSide:
}, BorderSide(color: Theme.of(context).primaryColor),
), )
SizedBox( //BorderRadius.all(Radius.circular(20));
height: 20, ),
), validator: (value) {
TextFormField( if (value.isEmpty) {
decoration: InputDecoration( return 'Please enter some text';
prefixIcon: Image.asset('assets/images/hospital_icon.png'), }
hintText: 'Select Project', return null;
hintStyle: TextStyle(fontSize:isSmallScreen?14:constraints.maxWidth*0.024) , },
enabledBorder: OutlineInputBorder( onSaved: (value){
borderRadius: BorderRadius.all(Radius.circular(20)), userInfo.Password = value;
borderSide: BorderSide(color: Hexcolor('#CCCCCC')),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(10.0)),
borderSide:
BorderSide(color: Theme.of(context).primaryColor),
)
//BorderRadius.all(Radius.circular(20));
),
validator: (value) {
if (value.isEmpty) {
return 'Please enter some text';
} }
return null; ),
}, SizedBox(
), height: 20,
SizedBox( ),
height: 20, TextFormField(
), decoration: InputDecoration(
Row( prefixIcon: Image.asset('assets/images/hospital_icon.png'),
mainAxisAlignment: MainAxisAlignment.spaceBetween, hintText: 'Select Project',
children: <Widget>[ hintStyle: TextStyle(
Container( fontSize:
child: Row( isSmallScreen ? 14 : constraints.maxWidth * 0.024),
mainAxisAlignment: MainAxisAlignment.start, enabledBorder: OutlineInputBorder(
children: <Widget>[ borderRadius: BorderRadius.all(Radius.circular(20)),
Checkbox( borderSide: BorderSide(color: Hexcolor('#CCCCCC')),
value: true, ),
activeColor: Theme.of(context).primaryColor, focusedBorder: OutlineInputBorder(
onChanged: (bool newValue) {}), borderRadius: BorderRadius.all(Radius.circular(10.0)),
Text("Remember me", style: TextStyle(fontSize:isSmallScreen?18:constraints.maxWidth*0.018)), borderSide:
], BorderSide(color: Theme.of(context).primaryColor),
), )
), //BorderRadius.all(Radius.circular(20));
RaisedButton( ),
onPressed: () { validator: (value) {
Navigator.of(context).pushNamed(HOME); if (value.isEmpty) {
}, return 'Please enter some text';
textColor: Colors.white, }
elevation: 0.0, return null;
padding: const EdgeInsets.all(0.0), },
shape: RoundedRectangleBorder( ),
borderRadius: BorderRadius.circular(10), SizedBox(
side: BorderSide(width: 0.5, color: Hexcolor('#CCCCCC'))), height: 20,
child: Container( ),
padding: const EdgeInsets.all(10.0), Row(
height: 50, mainAxisAlignment: MainAxisAlignment.spaceBetween,
width: 140, children: <Widget>[
Container(
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[ children: <Widget>[
Text('LOG IN', style: TextStyle(fontSize:isSmallScreen?20:constraints.maxWidth*0.020)), Checkbox(
Image.asset('assets/images/login_btn_arrow_icon.png') value: true,
activeColor: Theme.of(context).primaryColor,
onChanged: (bool newValue) {}),
Text("Remember me",
style: TextStyle(
fontSize: isSmallScreen
? 18
: constraints.maxWidth * 0.018)),
], ],
), ),
), ),
) RaisedButton(
], onPressed: () {
), login(context);
], },
textColor: Colors.white,
elevation: 0.0,
padding: const EdgeInsets.all(0.0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
side: BorderSide(width: 0.5, color: Hexcolor('#CCCCCC'))),
child: Container(
padding: const EdgeInsets.all(10.0),
height: 50,
width: 140,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text('LOG IN',
style: TextStyle(
fontSize: isSmallScreen
? 20
: constraints.maxWidth * 0.020)),
Image.asset('assets/images/login_btn_arrow_icon.png')
],
),
),
)
],
),
],
),
), ),
); );
}); });
} }
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