fix Authenticated User Object

merge-update-with-lab-changes
Mohammad Aljammal 5 years ago
parent 06416b4934
commit 53bbafdc2b

@ -2,16 +2,17 @@ import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart';
import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart';
class AuthenticatedUserObject{
class AuthenticatedUserObject {
AuthenticatedUser user;
AppSharedPreferences sharedPref = AppSharedPreferences();
bool isLogin = false;
AuthenticatedUserObject(){
AuthenticatedUserObject() {
getUser();
}
getUser() async {
if (user==null) {
if (user == null) {
var userData = await sharedPref.getObject(USER_PROFILE);
if (userData != null) user = AuthenticatedUser.fromJson(userData);
}
@ -20,4 +21,7 @@ class AuthenticatedUserObject{
this.isLogin = isLogin != null;
}
logout() async {
isLogin = false;
}
}

@ -17,6 +17,7 @@ class BaseService {
AppSharedPreferences sharedPref = AppSharedPreferences();
BaseService() {
authenticatedUserObject.getUser();
user = authenticatedUserObject.user;
// getUser();
}

@ -12,7 +12,7 @@ class MedicalViewModel extends BaseViewModel {
_medicalService.appoitmentAllHistoryResultList;
getAppointmentHistory() async {
if (authenticatedUserObject.isLogin) {
if (authenticatedUserObject.isLogin) {
setState(ViewState.Busy);
if (_medicalService.appoitmentAllHistoryResultList.length == 0)
await _medicalService.getAppointmentHistory();

@ -39,6 +39,7 @@ class _AllHabibMedicalServiceState extends State<AllHabibMedicalService> {
return AppScaffold(
isShowAppBar: true,
appBarTitle: TranslationBase.of(context).alhabiServices,
isShowDecPage: false,
body: Column(
children: [
Expanded(

@ -6,12 +6,12 @@ import 'package:flutter/material.dart';
import '../../uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/pages/ErService/widgets/card_common.dart';
class HmgServicePage extends StatefulWidget {
class ContactUsPage extends StatefulWidget {
@override
_HmgServicePageState createState() => _HmgServicePageState();
_ContactUsPageState createState() => _ContactUsPageState();
}
class _HmgServicePageState extends State<HmgServicePage> {
class _ContactUsPageState extends State<ContactUsPage> {
LocationUtils locationUtils;
@ -29,6 +29,7 @@ class _HmgServicePageState extends State<HmgServicePage> {
return AppScaffold(
isShowAppBar: true,//widget.isAppbar,
appBarTitle: "HMG Services",//TranslationBase.of(context).bookAppo,
isShowDecPage: false,
body: Container(
margin: EdgeInsets.fromLTRB(10.0, 20.0, 10.0, 10.0),
child: Column(

@ -2,7 +2,7 @@ import 'package:diplomaticquarterapp/config/size_config.dart';
import 'package:diplomaticquarterapp/core/viewModels/dashboard_view_model.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/pages/AlHabibMedicalService/all_habib_medical_service_page.dart';
import 'package:diplomaticquarterapp/pages/ContactUs/hmg_service.dart';
import 'package:diplomaticquarterapp/pages/ContactUs/contact_us_page.dart';
import 'package:diplomaticquarterapp/pages/ErService/ErOptions.dart';
import 'package:diplomaticquarterapp/pages/base/base_view.dart';
import 'package:diplomaticquarterapp/pages/feedback/feedback_home_page.dart';
@ -663,7 +663,7 @@ class _HomePageState extends State<HomePage> {
// Navigator.push(
// context, FadePage(page: FeedbackHomePage()));
Navigator.push(
context, FadePage(page: HmgServicePage()));
context, FadePage(page: ContactUsPage()));
},
child: Container(
width: double.infinity,

@ -1,5 +1,6 @@
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
import 'package:diplomaticquarterapp/config/size_config.dart';
import 'package:diplomaticquarterapp/core/service/AuthenticatedUserObject.dart';
import 'package:diplomaticquarterapp/core/viewModels/appointment_rate_view_model.dart';
import 'package:diplomaticquarterapp/locator.dart';
import 'package:diplomaticquarterapp/models/Authentication/check_activation_code_response.dart';
@ -40,6 +41,9 @@ class _Login extends State<Login> {
AppointmentRateViewModel appointmentRateViewModel =
locator<AppointmentRateViewModel>();
AuthenticatedUserObject authenticatedUserObject = locator<AuthenticatedUserObject>();
@override
void initState() {
// getDeviceToken();
@ -196,6 +200,7 @@ class _Login extends State<Login> {
// request.isRegister = false;
this.authService.checkActivationCode(request, code).then((result) => {
result = CheckActivationCode.fromJson(result),
authenticatedUserObject.getUser(),
this.sharedPref.setObject(USER_PROFILE, result.list),
this.sharedPref.setObject(LOGIN_TOKEN_ID, result.logInTokenID),
this.sharedPref.setString(TOKEN, result.authenticationTokenID),

@ -74,6 +74,7 @@ class _MedicalProfilePageState extends State<MedicalProfilePage> {
fit: BoxFit.cover,
width: double.infinity,
),
if(model.authenticatedUserObject.isLogin)
ListView.builder(
itemBuilder: (context, index) => TimeLineWidget(
isUp: index % 2 == 1,

@ -1,5 +1,6 @@
import 'package:diplomaticquarterapp/config/config.dart';
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
import 'package:diplomaticquarterapp/core/service/AuthenticatedUserObject.dart';
import 'package:diplomaticquarterapp/models/Authentication/check_activation_code_request.dart';
import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart';
import 'package:diplomaticquarterapp/models/Authentication/check_activation_code_response.dart';
@ -14,6 +15,8 @@ import 'package:diplomaticquarterapp/core/service/client/base_app_client.dart';
import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart';
import 'package:flutter/cupertino.dart';
import '../../locator.dart';
// SharedPreferences sharedPref = new SharedPreferences();
enum APP_STATUS { LOADING, UNAUTHENTICATED, AUTHENTICATED }
AppSharedPreferences sharedPref = new AppSharedPreferences();
@ -41,6 +44,8 @@ class AuthProvider with ChangeNotifier {
bool isLogin = false;
bool isLoading = true;
dynamic authenticatedUser;
AuthenticatedUserObject authenticatedUserObject = locator<AuthenticatedUserObject>();
AuthProvider() {
getUserAuthentication();
}

@ -1,4 +1,5 @@
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
import 'package:diplomaticquarterapp/core/service/AuthenticatedUserObject.dart';
import 'package:diplomaticquarterapp/core/service/client/base_app_client.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart';
@ -16,6 +17,7 @@ import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../config/size_config.dart';
import '../../locator.dart';
import 'drawer_item_widget.dart';
class AppDrawer extends StatefulWidget {
@ -34,6 +36,7 @@ class _AppDrawerState extends State<AppDrawer> {
var sharedPref = new AppSharedPreferences();
var familyFileProvider = FamilyFilesProvider();
AuthenticatedUser user;
AuthenticatedUserObject authenticatedUserObject = locator<AuthenticatedUserObject>();
@override
Widget build(BuildContext context) {
@ -329,10 +332,7 @@ class _AppDrawerState extends State<AppDrawer> {
}
logout() async {
// this.sharedPref.remove(USER_PROFILE);
// this.sharedPref.remove(IMEI_USER_DATA);
// this.sharedPref.remove(TOKEN);
// this.sharedPref.remove(LOGIN_TOKEN_ID);
authenticatedUserObject.logout();
await sharedPref.clear();
this.user = null;

Loading…
Cancel
Save