diff --git a/lib/main.dart b/lib/main.dart index 8b07dab4..a1ae6ac3 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,3 +1,4 @@ +import 'package:doctor_app_flutter/providers/auth_provider.dart'; import 'package:doctor_app_flutter/providers/patients_provider.dart'; import 'package:flutter/material.dart'; import 'package:hexcolor/hexcolor.dart'; @@ -12,6 +13,8 @@ class MyApp extends StatelessWidget { return MultiProvider( providers: [ ChangeNotifierProvider.value(value: PatientsProvider()), + ChangeNotifierProvider.value(value: AuthProvider()), + ], child: MaterialApp( title: 'Flutter Demo', diff --git a/lib/models/user_model.dart b/lib/models/user_model.dart new file mode 100644 index 00000000..74da3054 --- /dev/null +++ b/lib/models/user_model.dart @@ -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}); +} diff --git a/lib/providers/auth_provider.dart b/lib/providers/auth_provider.dart new file mode 100644 index 00000000..71cc3526 --- /dev/null +++ b/lib/providers/auth_provider.dart @@ -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 login(UserModel userInfo) async { + Map 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); + } + } +} diff --git a/lib/providers/patients_provider.dart b/lib/providers/patients_provider.dart index 475d23a0..dfdc8848 100644 --- a/lib/providers/patients_provider.dart +++ b/lib/providers/patients_provider.dart @@ -1,9 +1,8 @@ -import 'dart:io'; +import 'dart:convert'; import 'package:doctor_app_flutter/models/patient_model.dart'; import 'package:flutter/cupertino.dart'; import 'package:http/http.dart' as http; -import 'dart:convert'; class PatientsProvider with ChangeNotifier { Future getPatientList(PatientModel patient, patientType) async { @@ -30,7 +29,7 @@ class PatientsProvider with ChangeNotifier { "To": patient.To, "LanguageID": patient.LanguageID, "stamp": patient.stamp, - "IPAdress":patient.IPAdress, + "IPAdress": patient.IPAdress, "VersionID": patient.VersionID, "Channel": patient.Channel, "TokenID": patient.TokenID, diff --git a/lib/providers/providers.init b/lib/providers/providers.init deleted file mode 100644 index e69de29b..00000000 diff --git a/lib/screens/auth/login_screen.dart b/lib/screens/auth/login_screen.dart index f0140f80..ae2bd863 100644 --- a/lib/screens/auth/login_screen.dart +++ b/lib/screens/auth/login_screen.dart @@ -1,15 +1,14 @@ +import 'dart:async'; + +import 'package:flutter/material.dart'; import 'package:shared_preferences/shared_preferences.dart'; import '../../widgets/auth/auth_header.dart'; import '../../widgets/auth/login_form.dart'; -import 'package:flutter/material.dart'; -import 'dart:async'; class Loginsreen extends StatelessWidget { // Future pref = SharedPreferences.getInstance(); Future _prefs = SharedPreferences.getInstance(); - // final SharedPreferences prefs = await _prefs; - Future _incrementCounter() async { final SharedPreferences prefs = await _prefs; final int counter = (prefs.getInt('counter') ?? 0) + 1; @@ -23,6 +22,7 @@ class Loginsreen extends StatelessWidget { } @override Widget build(BuildContext context) { + // prefs.setInt("counter", 1); _incrementCounter(); return Scaffold( diff --git a/lib/widgets/auth/login_form.dart b/lib/widgets/auth/login_form.dart index a1b07060..4c3df702 100644 --- a/lib/widgets/auth/login_form.dart +++ b/lib/widgets/auth/login_form.dart @@ -1,150 +1,203 @@ +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/rendering.dart'; import 'package:hexcolor/hexcolor.dart'; + + class LoginForm extends StatelessWidget { - const LoginForm({ + LoginForm({ Key key, }) : super(key: key); - + + final loginFormKey = GlobalKey(); + var userInfo = UserModel( + UserID: '', + Password: '', + ProjectID: 15, + LanguageID: 2, + IPAdress: "11.11.11.11", + VersionID: 1.2, + Channel: 9, + SessionID: "i1UJwCTSqt" + ); @override Widget build(BuildContext context) { - - return LayoutBuilder(builder: (ctx, constraints) { - var smallScreenSize = 660; - bool isSmallScreen = constraints.maxWidth<=smallScreenSize; - return Container( - width: constraints.maxWidth * 0.9, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - SizedBox( - height: 20, - ), - TextFormField( - decoration: InputDecoration( - prefixIcon: Image.asset('assets/images/user_id_icon.png'), - hintText: 'Enter ID', - hintStyle: TextStyle(fontSize:isSmallScreen?14:constraints.maxWidth*0.024) , - enabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.all(Radius.circular(20)), - 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, - ), - TextFormField( - obscureText: true, - decoration: InputDecoration( - prefixIcon: Image.asset('assets/images/password_icon.png'), - hintText: 'Enter Password', - hintStyle: TextStyle(fontSize:isSmallScreen?14:constraints.maxWidth*0.024) , - enabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.all(Radius.circular(20)), - 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, - ), - TextFormField( - decoration: InputDecoration( - prefixIcon: Image.asset('assets/images/hospital_icon.png'), - hintText: 'Select Project', - hintStyle: TextStyle(fontSize:isSmallScreen?14:constraints.maxWidth*0.024) , - enabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.all(Radius.circular(20)), - 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'; + var smallScreenSize = 660; + bool isSmallScreen = constraints.maxWidth <= smallScreenSize; + return Form( + key: loginFormKey, + child: Container( + width: constraints.maxWidth * 0.9, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SizedBox( + height: 20, + ), + TextFormField( + decoration: InputDecoration( + prefixIcon: Image.asset('assets/images/user_id_icon.png'), + hintText: 'Enter ID', + hintStyle: TextStyle( + fontSize: + isSmallScreen ? 14 : constraints.maxWidth * 0.024), + enabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.all(Radius.circular(20)), + 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; + }, + onSaved: (value){ + userInfo.UserID = value; + }, + ), + SizedBox( + height: 20, + ), + TextFormField( + obscureText: true, + decoration: InputDecoration( + prefixIcon: Image.asset('assets/images/password_icon.png'), + hintText: 'Enter Password', + hintStyle: TextStyle( + fontSize: + isSmallScreen ? 14 : constraints.maxWidth * 0.024), + enabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.all(Radius.circular(20)), + 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; + }, + onSaved: (value){ + userInfo.Password = value; } - return null; - }, - ), - SizedBox( - height: 20, - ), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Container( - child: Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Checkbox( - value: true, - activeColor: Theme.of(context).primaryColor, - onChanged: (bool newValue) {}), - Text("Remember me", style: TextStyle(fontSize:isSmallScreen?18:constraints.maxWidth*0.018)), - ], - ), - ), - RaisedButton( - onPressed: () { - Navigator.of(context).pushNamed(HOME); - }, - 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, + ), + SizedBox( + height: 20, + ), + TextFormField( + decoration: InputDecoration( + prefixIcon: Image.asset('assets/images/hospital_icon.png'), + hintText: 'Select Project', + hintStyle: TextStyle( + fontSize: + isSmallScreen ? 14 : constraints.maxWidth * 0.024), + enabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.all(Radius.circular(20)), + 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, + ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Container( child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, + mainAxisAlignment: MainAxisAlignment.start, children: [ - Text('LOG IN', style: TextStyle(fontSize:isSmallScreen?20:constraints.maxWidth*0.020)), - Image.asset('assets/images/login_btn_arrow_icon.png') + Checkbox( + 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: [ + 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(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'); + }); + } } diff --git a/pubspec.lock b/pubspec.lock index 7c920531..a1adef56 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -275,6 +275,13 @@ packages: url: "https://pub.dartlang.org" source: hosted 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: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index c5067eb7..b6ebd663 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -26,6 +26,8 @@ dependencies: provider: ^3.0.0 i18n: any shared_preferences: ^0.5.6+3 + imei_plugin: ^1.1.6 + # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons.