first step form real login and calling Api
parent
da3cc456ba
commit
7227c71393
@ -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,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');
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue