From 6e152951b4ec4d6dbcd79bb0b1f089cfc4a5c76e Mon Sep 17 00:00:00 2001 From: Sultan Khan Date: Sat, 21 Nov 2020 10:39:30 +0300 Subject: [PATCH] notification count --- lib/pages/landing/landing_page.dart | 132 ++++++++++++------ lib/pages/settings/general_setting.dart | 40 +++++- .../authentication/auth_provider.dart | 31 +++- .../permission/permission_service.dart | 8 +- lib/widgets/buttons/button.dart | 2 +- lib/widgets/buttons/defaultButton.dart | 2 +- lib/widgets/buttons/floatingActionButton.dart | 5 +- lib/widgets/buttons/mini_button.dart | 7 +- lib/widgets/buttons/secondary_button.dart | 7 +- 9 files changed, 177 insertions(+), 57 deletions(-) diff --git a/lib/pages/landing/landing_page.dart b/lib/pages/landing/landing_page.dart index 3b6aee91..7879ab0d 100644 --- a/lib/pages/landing/landing_page.dart +++ b/lib/pages/landing/landing_page.dart @@ -47,6 +47,7 @@ class _LandingPageState extends State with WidgetsBindingObserver { int currentTab = 0; PageController pageController; ProjectViewModel projectProvider; + var notificationCount = ''; ///inject the user data AuthenticatedUserObject authenticatedUserObject = @@ -87,33 +88,33 @@ class _LandingPageState extends State with WidgetsBindingObserver { } //setState(() { - print("didChangeAppLifecycleState"); - print('state = $state'); - AppGlobal.context = context; - if (state == AppLifecycleState.resumed) { - print(LandingPage.isOpenCallPage); - if (LandingPage.isOpenCallPage) { - if (!isPageNavigated) { - isPageNavigated = true; - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => IncomingCall( - incomingCallData: LandingPage.incomingCallData))) - .then((value) { - isPageNavigated = false; - }); - } + print("didChangeAppLifecycleState"); + print('state = $state'); + AppGlobal.context = context; + if (state == AppLifecycleState.resumed) { + print(LandingPage.isOpenCallPage); + if (LandingPage.isOpenCallPage) { + if (!isPageNavigated) { + isPageNavigated = true; + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => IncomingCall( + incomingCallData: LandingPage.incomingCallData))) + .then((value) { + isPageNavigated = false; + }); } } + } - if (state == AppLifecycleState.paused) { - isPageNavigated = false; - } + if (state == AppLifecycleState.paused) { + isPageNavigated = false; + } - if (state == AppLifecycleState.inactive) { - isPageNavigated = false; - } + if (state == AppLifecycleState.inactive) { + isPageNavigated = false; + } //}); } @@ -128,8 +129,8 @@ class _LandingPageState extends State with WidgetsBindingObserver { super.initState(); WidgetsBinding.instance.addObserver(this); //setState(() { - AppGlobal.context = context; - // }); + AppGlobal.context = context; + // }); _requestIOSPermissions(); pageController = PageController(keepPage: true); _firebaseMessaging.setAutoInitEnabled(true); @@ -140,7 +141,7 @@ class _LandingPageState extends State with WidgetsBindingObserver { _firebaseMessaging.getToken().then((String token) { sharedPref.setString(PUSH_TOKEN, token); - if (token != null && DEVICE_TOKEN =="") { + if (token != null && DEVICE_TOKEN == "") { DEVICE_TOKEN = token; checkUserStatus(token); } @@ -344,34 +345,69 @@ class _LandingPageState extends State with WidgetsBindingObserver { ), title: Text( getText(currentTab).toUpperCase(), - style: TextStyle(fontWeight: FontWeight.bold,color: Colors.white,fontFamily: projectViewModel.isArabic ? 'Cairo' : 'WorkSans'), + style: TextStyle( + fontWeight: FontWeight.bold, + color: Colors.white, + fontFamily: projectViewModel.isArabic ? 'Cairo' : 'WorkSans'), // bold: true, // color: Colors.white, ), leading: Builder( builder: (BuildContext context) { - return IconButton( - icon: Icon(Icons.menu), - color: Colors.white, - onPressed: () => Scaffold.of(context).openDrawer(), + return new Stack( + children: [ + IconButton( + icon: Icon(Icons.menu), + color: Colors.white, + onPressed: () => Scaffold.of(context).openDrawer(), + ), + notificationCount != '' + ? new Positioned( + right: 0, + top: 10, + child: new Container( + padding: EdgeInsets.all(4), + decoration: new BoxDecoration( + color: Colors.red, + borderRadius: BorderRadius.circular(20), + ), + constraints: BoxConstraints( + minWidth: 20, + minHeight: 20, + ), + child: new Text( + notificationCount, + style: new TextStyle( + color: Colors.white, + fontSize: 9, + ), + textAlign: TextAlign.center, + ), + ), + ) + : SizedBox() + ], ); }, ), actions: [ IconButton( - //iconSize: 70, - icon: Icon(projectViewModel.isLogin?Icons.settings : Icons.login,color: Colors.white,), - onPressed: () { - if(projectViewModel.isLogin) + //iconSize: 70, + icon: Icon( + projectViewModel.isLogin ? Icons.settings : Icons.login, + color: Colors.white, + ), + onPressed: () { + if (projectViewModel.isLogin) + Navigator.of(context).pushNamed( + SETTINGS, + ); + else Navigator.of(context).pushNamed( - SETTINGS , + WELCOME_LOGIN, ); - else - Navigator.of(context).pushNamed( - WELCOME_LOGIN , - ); - }, //do something, - ) + }, //do something, + ) ], centerTitle: true, ), @@ -388,7 +424,7 @@ class _LandingPageState extends State with WidgetsBindingObserver { ), MedicalProfilePage(), BookingOptions(), - MyFamily(isAppbarVisible:false), + MyFamily(isAppbarVisible: false), ToDo(), ], // Please do not remove the BookingOptions from this array ), @@ -432,11 +468,17 @@ class _LandingPageState extends State with WidgetsBindingObserver { if (await sharedPref.getObject(USER_PROFILE) != null) { var data = AuthenticatedUser.fromJson(await sharedPref.getObject(USER_PROFILE)); - if (data != null) + if (data != null) { authService .registeredAuthenticatedUser(data, token, 0, 0) .then((res) => {print(res)}); - + authService.getDashboard().then((value) => { + setState(() { + notificationCount = value['List_PatientDashboard'] + [0]['UnreadPatientNotificationCount'].toString(); + }) + }); + } } } diff --git a/lib/pages/settings/general_setting.dart b/lib/pages/settings/general_setting.dart index 7fef62a5..05e02a86 100644 --- a/lib/pages/settings/general_setting.dart +++ b/lib/pages/settings/general_setting.dart @@ -236,7 +236,43 @@ class _GeneralSettings extends State break; case 1: { - themeNotifier.setTheme(await getTheme(value)); + themeNotifier.setTheme(ThemeData( + fontFamily: await sharedPref.getString(APP_LANGUAGE) == 'ar' ? 'Cairo' : 'WorkSans', + primarySwatch: Colors.grey, + visualDensity: VisualDensity.adaptivePlatformDensity, + brightness: Brightness.light, + pageTransitionsTheme: const PageTransitionsTheme( + builders: { + TargetPlatform.android: ZoomPageTransitionsBuilder(), + TargetPlatform.iOS: CupertinoPageTransitionsBuilder(), + }, + ), + hintColor: Colors.grey[400], + cardColor: Colors.black, + buttonColor: Colors.grey[400], + disabledColor: Colors.grey[300], + errorColor: Color.fromRGBO(235, 80, 60, 1.0), + scaffoldBackgroundColor: Colors.grey, + textSelectionColor: Color.fromRGBO(80, 100, 253, 0.5), + textSelectionHandleColor: Colors.grey, + canvasColor: Colors.white, + backgroundColor: Colors.grey, + highlightColor: Colors.grey[100].withOpacity(0.4), + splashColor: Colors.transparent, + primaryColor: Colors.grey, + bottomSheetTheme: BottomSheetThemeData(backgroundColor: Color(0xffE0E0E0)), + cursorColor: Colors.grey, + + iconTheme: IconThemeData(), + appBarTheme: AppBarTheme( + color: Colors.grey, + brightness: Brightness.dark, + elevation: 10.0, + actionsIconTheme: IconThemeData( + color: Colors.grey, + ), + ), + )); Screen.setBrightness(1.0); } break; @@ -257,7 +293,7 @@ class _GeneralSettings extends State } break; } - permission.setTheme(value); + //permission.setTheme(value); } setVibration(value){ diff --git a/lib/services/authentication/auth_provider.dart b/lib/services/authentication/auth_provider.dart index d9d829e9..1e5e4ad2 100644 --- a/lib/services/authentication/auth_provider.dart +++ b/lib/services/authentication/auth_provider.dart @@ -47,6 +47,7 @@ const LOGGED_IN_USER_URL = const FORGOT_PATIENT_ID = 'Services/Authentication.svc/REST/SendPatientIDSMSByMobileNumber'; +const DASHBOARD = 'Services/Patients.svc/REST/PatientDashboard'; class AuthProvider with ChangeNotifier { bool isLogin = false; @@ -370,7 +371,8 @@ class AuthProvider with ChangeNotifier { Future sendPatientIDSMS(mobileNo, context) async { Map request; - var languageID = await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar'); + var languageID = + await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar'); Request req = appGlobal.getPublicRequest(); request = { "LanguageID": languageID == 'ar' ? 1 : 2, @@ -427,4 +429,31 @@ class AuthProvider with ChangeNotifier { //return Future.value(error); } } + + Future getDashboard() async { + Map request = {}; + request['VersionID'] = VERSION_ID; + request['Channel'] = CHANNEL; + request['IPAdress'] = IP_ADDRESS; + request['generalid'] = GENERAL_ID; + request['LanguageID'] = LANGUAGE_ID; + request['DeviceTypeID'] = DeviceTypeID; + request["PatientTypeID"] = 1; + request["PatientType"] = 1; + dynamic localRes; + try { + await new BaseAppClient().post(DASHBOARD, + onSuccess: (dynamic response, int statusCode) { + localRes = response; //CheckActivationCode.fromJson(); + }, onFailure: (String error, int statusCode) { + localRes = error; + return Future.value(error); + // throw error; + }, body: request); + return Future.value(localRes); + } catch (error) { + throw error; + //return Future.value(error); + } + } } diff --git a/lib/services/permission/permission_service.dart b/lib/services/permission/permission_service.dart index 292724f2..281ec14c 100644 --- a/lib/services/permission/permission_service.dart +++ b/lib/services/permission/permission_service.dart @@ -6,6 +6,7 @@ import 'package:diplomaticquarterapp/models/Request.dart'; import 'package:diplomaticquarterapp/services/authentication/auth_provider.dart'; import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:localstorage/localstorage.dart'; class PermissionService extends BaseService { @@ -18,7 +19,12 @@ class PermissionService extends BaseService { } isVibrationEnabled() { - return storage.getItem('isVibration'); + return storage.getItem('isVibration') ==null ? false :true; + } + vibrate(){ + if(isVibrationEnabled() ==true){ + HapticFeedback.vibrate(); + } } diff --git a/lib/widgets/buttons/button.dart b/lib/widgets/buttons/button.dart index 5b0e6489..597106c9 100644 --- a/lib/widgets/buttons/button.dart +++ b/lib/widgets/buttons/button.dart @@ -90,7 +90,7 @@ class _ButtonState extends State