From 3df0443992f14d9ff5bbd4d268050c810d0123ea Mon Sep 17 00:00:00 2001 From: "snehalathad@aissel.com" Date: Thu, 19 Dec 2024 15:59:43 +0530 Subject: [PATCH] updated changes --- assets/api_constants.json | 22 ++-- ios/Podfile.lock | 6 ++ lib/main.dart | 3 +- lib/model/hive_api_constants.g.dart | 7 +- lib/utils/apicall.dart | 125 +++++++++++------------ lib/utils/constants.dart | 2 +- lib/view/eventslist.dart | 117 ++++++++++++--------- lib/view/home.dart | 17 +++ lib/view/insights.dart | 8 +- lib/view/login.dart | 33 +++--- lib/view/login_components/care_view.dart | 28 ++--- lib/widgets/home_drawer.dart | 25 +++-- 12 files changed, 229 insertions(+), 164 deletions(-) diff --git a/assets/api_constants.json b/assets/api_constants.json index bd35e33..e55c509 100644 --- a/assets/api_constants.json +++ b/assets/api_constants.json @@ -3,68 +3,68 @@ "api": "loadFutureEvents", "interval": 0, "method": "POST", - "module": "apis/v1/events" + "module": "apis/v1/events/" }, { "api": "saveUserInterestedEvent", "interval": 0, "method": "POST", - "module": "apis/v1/events" + "module": "apis/v1/events/" }, { "api": "saveUserAttendingEvent", "interval": 0, "method": "POST", - "module": "apis/v1/events" + "module": "apis/v1/events/" }, { "api": "eventOverview", "interval": 0, "method": "POST", - "module": "apis/v1/events" + "module": "apis/v1/events/" }, { "api": "getSpecialitiesDonutChart", "interval": 0, "method": "POST", - "module": "apis/v1/events" + "module": "apis/v1/events/" }, { "api": "getTopicCloudChart", "interval": 0, "method": "POST", - "module": "apis/v1/events" + "module": "apis/v1/events/" }, { "api": "getTopAffiliationBarChart", "interval": 0, "method": "POST", - "module": "apis/v1/events" + "module": "apis/v1/events/" }, { "api": "eventSpeakers", "interval": 0, "method": "POST", - "module": "apis/v1/events" + "module": "apis/v1/events/" }, { "api": "saveEventsTopicNote", "interval": 5, "method": "POST", - "module": "apis/v1/events" + "module": "apis/v1/events/" }, { "api": "eventUserAnalytics", "interval": 0, "method": "POST", - "module": "apis/v1/events" + "module": "apis/v1/events/" }, { "api": "saveEventOffline", "interval": 0, "method": "POST", - "module": "apis/v1/events" + "module": "apis/v1/events/" }, { "api": "contactslistapi", diff --git a/ios/Podfile.lock b/ios/Podfile.lock index a7979f8..95ac6d9 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -74,6 +74,8 @@ PODS: - FirebaseRemoteConfigInterop (10.25.0) - FirebaseSharedSwift (10.25.0) - Flutter (1.0.0) + - flutter_background_service_ios (0.0.3): + - Flutter - GoogleUtilities/Environment (7.13.3): - GoogleUtilities/Privacy - PromisesObjC (< 3.0, >= 1.2) @@ -120,6 +122,7 @@ DEPENDENCIES: - firebase_core (from `.symlinks/plugins/firebase_core/ios`) - firebase_remote_config (from `.symlinks/plugins/firebase_remote_config/ios`) - Flutter (from `Flutter`) + - flutter_background_service_ios (from `.symlinks/plugins/flutter_background_service_ios/ios`) - image_picker_ios (from `.symlinks/plugins/image_picker_ios/ios`) - mobile_device_identifier (from `.symlinks/plugins/mobile_device_identifier/ios`) - open_file (from `.symlinks/plugins/open_file/ios`) @@ -160,6 +163,8 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/firebase_remote_config/ios" Flutter: :path: Flutter + flutter_background_service_ios: + :path: ".symlinks/plugins/flutter_background_service_ios/ios" image_picker_ios: :path: ".symlinks/plugins/image_picker_ios/ios" mobile_device_identifier: @@ -194,6 +199,7 @@ SPEC CHECKSUMS: FirebaseRemoteConfigInterop: b25018791b204c0d78a90e394d6c62d9b1f22da8 FirebaseSharedSwift: 0274086954b1b2d5fd7e829eccc587044d72a4ba Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7 + flutter_background_service_ios: e30e0d3ee69e4cee66272d0c78eacd48c2e94aac GoogleUtilities: ea963c370a38a8069cc5f7ba4ca849a60b6d7d15 image_picker_ios: b545a5f16c0fa88e3ecbbce3ed4de45567a8ec18 JNKeychain: fb6cc9ec95959ba46cd95d0ee6f7a05e41da9f42 diff --git a/lib/main.dart b/lib/main.dart index efd1b4e..ede330f 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -520,10 +520,11 @@ import 'contacts_module/provider_class/award_provider.dart'; import 'firebase_options.dart'; import 'package:flutter_background_service/flutter_background_service.dart'; +late SharedPreferences sp; Future main() async { WidgetsFlutterBinding.ensureInitialized(); // startPeriodicCalls(); - + sp = await SharedPreferences.getInstance(); await Hive.initFlutter(); await initializeService(); diff --git a/lib/model/hive_api_constants.g.dart b/lib/model/hive_api_constants.g.dart index 78f5a4f..668fb27 100644 --- a/lib/model/hive_api_constants.g.dart +++ b/lib/model/hive_api_constants.g.dart @@ -21,13 +21,14 @@ class HiveApiConstantsAdapter extends TypeAdapter { interval: fields[1] as int?, method: fields[2] as String?, module: fields[3] as String?, + hivename: fields[4] as String?, ); } @override void write(BinaryWriter writer, HiveApiConstants obj) { writer - ..writeByte(4) + ..writeByte(5) ..writeByte(0) ..write(obj.functionName) ..writeByte(1) @@ -35,7 +36,9 @@ class HiveApiConstantsAdapter extends TypeAdapter { ..writeByte(2) ..write(obj.method) ..writeByte(3) - ..write(obj.module); + ..write(obj.module) + ..writeByte(4) + ..write(obj.hivename); } @override diff --git a/lib/utils/apicall.dart b/lib/utils/apicall.dart index 96fe4e0..0b11d59 100644 --- a/lib/utils/apicall.dart +++ b/lib/utils/apicall.dart @@ -4,6 +4,7 @@ import 'dart:io'; import 'package:dio/dio.dart'; import 'package:dio/io.dart'; import 'package:flutter/services.dart'; +import 'package:konectar_events/main.dart'; import 'package:konectar_events/model/affiliationsmodel.dart'; import 'package:konectar_events/model/allsessionnotesmodel.dart'; import 'package:konectar_events/model/api_constants_model.dart'; @@ -30,19 +31,9 @@ import 'package:http/http.dart' as http; class ApiCall { final dio = Dio(); - final Future _prefs = SharedPreferences.getInstance(); - String token = ""; - ApiCall() { - init(); - print("constructor"); - } - - init() async { - token = await _prefs.then((SharedPreferences prefs) { - return prefs.getString('token') ?? ""; - }); - } + String token = sp.getString('token') ?? ""; + String global_url = sp.getString('url') ?? ""; //K1 API CALLS Future parseInfo() async { @@ -140,15 +131,16 @@ class ApiCall { 'type': type ?? 1, }); // "end": DateTime(2024, 12, 14).toIso8601String(), - token = await _prefs.then((SharedPreferences prefs) { - return prefs.getString('token') ?? ""; - }); + // token = sp.getString('token') ?? ""; + // await _prefs.then((SharedPreferences prefs) { + // return prefs.getString('token') ?? ""; + // }); print("SAVED TOKEN :${token}"); //http://192.168.2.130/konectar-staging/apiauths/logout/ try { response = await dio.post( - '${EventsConstants.url}${EventsConstants.eventslistapi}', + '${global_url}${EventsConstants.moduleName}${EventsConstants.eventslistapi}', options: Options( followRedirects: true, validateStatus: (status) => true, @@ -185,12 +177,12 @@ class ApiCall { return client; }; Response response; - String token = await _prefs.then((SharedPreferences prefs) { - return prefs.getString('token') ?? ""; - }); + // String token = await _prefs.then((SharedPreferences prefs) { + // return prefs.getString('token') ?? ""; + // }); var formData = FormData.fromMap({"eid": eventid, "flag": flag}); response = await dio.post( - '${EventsConstants.url}${EventsConstants.followUnfollowEvent}', + '${global_url}${EventsConstants.moduleName}${EventsConstants.followUnfollowEvent}', options: Options( followRedirects: true, validateStatus: (status) => true, @@ -221,13 +213,13 @@ class ApiCall { (X509Certificate cert, String host, int port) => true; return client; }; - String token = await _prefs.then((SharedPreferences prefs) { - return prefs.getString('token') ?? ""; - }); + // String token = await _prefs.then((SharedPreferences prefs) { + // return prefs.getString('token') ?? ""; + // }); Response response; var formData = FormData.fromMap({"eid": eventid, "flag": flag}); response = await dio.post( - '${EventsConstants.url}${EventsConstants.attendNotAttendEvent}', + '${global_url}${EventsConstants.moduleName}${EventsConstants.attendNotAttendEvent}', options: Options( followRedirects: true, validateStatus: (status) => true, @@ -256,9 +248,9 @@ class ApiCall { required String endDate, required bool client, }) async { - String token = await _prefs.then((SharedPreferences prefs) { - return prefs.getString('token') ?? ""; - }); + // String token = await _prefs.then((SharedPreferences prefs) { + // return prefs.getString('token') ?? ""; + // }); print( "FORMAT_CHECK_DATE $startDate $endDate $eventid ${DateTime(2024, 12, 03).toIso8601String()}"); Dio dio = Dio(); @@ -289,7 +281,7 @@ class ApiCall { print("FORMDATA:${formData.toString()},$startDate,$endDate"); response = await dio.post( - '${EventsConstants.url}${EventsConstants.specialtyOfSpeakers}', + '${global_url}${EventsConstants.moduleName}${EventsConstants.specialtyOfSpeakers}', options: Options( followRedirects: true, validateStatus: (status) => true, @@ -320,9 +312,9 @@ class ApiCall { required String startDate, required String endDate, required bool client}) async { - String token = await _prefs.then((SharedPreferences prefs) { - return prefs.getString('token') ?? ""; - }); + // String token = await _prefs.then((SharedPreferences prefs) { + // return prefs.getString('token') ?? ""; + // }); Dio dio = Dio(); (dio.httpClientAdapter as IOHttpClientAdapter).onHttpClientCreate = (HttpClient client) { @@ -350,7 +342,7 @@ class ApiCall { print("FORMDATA:${formData.toString()},$startDate,$endDate"); response = await dio.post( - '${EventsConstants.url}${EventsConstants.insightsTopicsCloud}', + '${global_url}${EventsConstants.moduleName}${EventsConstants.insightsTopicsCloud}', options: Options( followRedirects: true, validateStatus: (status) => true, @@ -383,9 +375,9 @@ class ApiCall { required String startDate, required String endDate, required bool client}) async { - String token = await _prefs.then((SharedPreferences prefs) { - return prefs.getString('token') ?? ""; - }); + // String token = await _prefs.then((SharedPreferences prefs) { + // return prefs.getString('token') ?? ""; + // }); Dio dio = Dio(); (dio.httpClientAdapter as IOHttpClientAdapter).onHttpClientCreate = (HttpClient client) { @@ -413,7 +405,7 @@ class ApiCall { print("FORMDATA:${formData.toString()},$startDate,$endDate"); response = await dio.post( - '${EventsConstants.url}${EventsConstants.insightsBarChart}', + '${global_url}${EventsConstants.moduleName}${EventsConstants.insightsBarChart}', options: Options( followRedirects: true, validateStatus: (status) => true, @@ -453,11 +445,11 @@ class ApiCall { var formData = FormData.fromMap({ "event_id": eventid, }); - String token = await _prefs.then((SharedPreferences prefs) { - return prefs.getString('token') ?? ""; - }); + // String token = await _prefs.then((SharedPreferences prefs) { + // return prefs.getString('token') ?? ""; + // }); response = await dio.post( - '${EventsConstants.url}${EventsConstants.eventdetailsapi}', + '${global_url}${EventsConstants.moduleName}${EventsConstants.eventdetailsapi}', options: Options( followRedirects: true, validateStatus: (status) => true, @@ -498,11 +490,11 @@ class ApiCall { }); // "sd": "2024-07-30", // "ed": "2024-08-03", - String token = await _prefs.then((SharedPreferences prefs) { - return prefs.getString('token') ?? ""; - }); + // String token = await _prefs.then((SharedPreferences prefs) { + // return prefs.getString('token') ?? ""; + // }); response = await dio.post( - '${EventsConstants.url}${EventsConstants.speakerslistapi}', + '${global_url}${EventsConstants.moduleName}${EventsConstants.speakerslistapi}', options: Options( followRedirects: true, validateStatus: (status) => true, @@ -544,11 +536,11 @@ class ApiCall { "k_id": kid, }); // "proj_kol_id": 0, - String token = await _prefs.then((SharedPreferences prefs) { - return prefs.getString('token') ?? ""; - }); + // String token = await _prefs.then((SharedPreferences prefs) { + // return prefs.getString('token') ?? ""; + // }); response = await dio.post( - '${EventsConstants.url}${EventsConstants.showEventsTopicsAndSession}', + '${global_url}${EventsConstants.moduleName}${EventsConstants.showEventsTopicsAndSession}', options: Options( followRedirects: true, validateStatus: (status) => true, @@ -593,9 +585,9 @@ class ApiCall { return client; }; var formData; - String token = await _prefs.then((SharedPreferences prefs) { - return prefs.getString('token') ?? ""; - }); + // String token = await _prefs.then((SharedPreferences prefs) { + // return prefs.getString('token') ?? ""; + // }); Response response; if (filename != "") { formData = FormData.fromMap({ @@ -618,7 +610,7 @@ class ApiCall { // "/Users/aissel/Library/Developer/CoreSimulator/Devices/1E435121-7E65-45C6-9E0B-411C8B9915F5/data/Containers/Data/Application/3CBC1CFF-79AD-49FA-A6E0-13D0AA2959D2/tmp/Flutter Questionaire.pdf", response = await dio.post( - '${EventsConstants.url}${EventsConstants.saveEventsTopicNote}', + '${global_url}${EventsConstants.moduleName}${EventsConstants.saveEventsTopicNote}', options: Options( followRedirects: true, validateStatus: (status) => true, @@ -651,15 +643,15 @@ class ApiCall { return client; }; Response response; - String token = await _prefs.then((SharedPreferences prefs) { - return prefs.getString('token') ?? ""; - }); + // String token = await _prefs.then((SharedPreferences prefs) { + // return prefs.getString('token') ?? ""; + // }); var formData = FormData.fromMap({ "kol_events_id": eventid, }); // "proj_kol_id": 0, response = await dio.post( - '${EventsConstants.url}${EventsConstants.eventUserAnalytics}', + '${global_url}${EventsConstants.moduleName}${EventsConstants.eventUserAnalytics}', options: Options( followRedirects: true, validateStatus: (status) => true, @@ -690,9 +682,9 @@ class ApiCall { dynamic jsonResult = jsonDecode(await rootBundle.loadString("assets/api_constants.json")); //dynamic jsonResult = await MockApiCall().getConfigDataMedical(); - String token = await _prefs.then((SharedPreferences prefs) { - return prefs.getString('token') ?? ""; - }); + // String token = await _prefs.then((SharedPreferences prefs) { + // return prefs.getString('token') ?? ""; + // }); List responseData = apiConstantsResponseFromJson(jsonResult); print('Response_data_is: $responseData'); @@ -775,7 +767,7 @@ class ApiCall { response = await dio.post( //'http://192.168.2.130/konectar-staging/apiauths/login', //'http://192.168.2.130/konectar-staging/apiauths/login/', - '${EventsConstants.loginUrl}${EventsConstants.login}', + '${global_url}${EventsConstants.loginmodule}${EventsConstants.login}', options: Options(), data: formData); if (response.statusCode == 200) { @@ -800,9 +792,9 @@ class ApiCall { return client; }; print("email : $email,device : $deviceid"); - String token = await _prefs.then((SharedPreferences prefs) { - return prefs.getString('token') ?? ""; - }); + // String token = await _prefs.then((SharedPreferences prefs) { + // return prefs.getString('token') ?? ""; + // }); Response response; print("url :${EventsConstants.loginUrl}${EventsConstants.logout}/"); var formData = FormData.fromMap({ @@ -828,12 +820,17 @@ class ApiCall { // "token": token, // }, ); + if (response.statusCode == 200) { print("response user LoGOUT!!!!!!!!!!!!!!!!!!!!! \n ${response.data} "); + + VerificationResponse verificationResponse = + verificationResponseFromJson(response.data); + return verificationResponse; } print(response.data.toString()); - return response.data; + return ""; } //************ K2 API CALLS *********************************************************************************************************************************** diff --git a/lib/utils/constants.dart b/lib/utils/constants.dart index 6b5a1e7..2a41651 100644 --- a/lib/utils/constants.dart +++ b/lib/utils/constants.dart @@ -21,7 +21,7 @@ class EventsConstants { //192.0.0.2:8007 - iphone // 192.168.2.109:8007 - office jkqehjkq //K1 API~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - static const String moduleName = "apis/v1/events"; + static const String moduleName = "apis/v1/events/"; static const String loginmodule = "apiauths"; static const String stagingUrl = diff --git a/lib/view/eventslist.dart b/lib/view/eventslist.dart index c34bd0e..9f66358 100644 --- a/lib/view/eventslist.dart +++ b/lib/view/eventslist.dart @@ -66,6 +66,8 @@ class _EventsListingScreenState extends State pagingController.addPageRequestListener((pageKey) { _fetchPages(pageKey, provider); }); + pagingController.addStatusListener(_showError); + pagingController.error = "No Speakers"; } Future _fetchPage(int pageKey) async { @@ -101,7 +103,7 @@ class _EventsListingScreenState extends State pagingController.appendPage(newItems, nextPageKey); } } catch (error) { - pagingController.error = error; + pagingController.error = "Speakers not Available"; } // } } @@ -110,15 +112,51 @@ class _EventsListingScreenState extends State List list = await provider .getInitialSpeakersDetails(widget.event.id!, searchkey: searchSpeaker); print("CHECK LENGTH ${list.length}"); - final isLastPage = pageKey + _pageSize >= list.length; - final nextItems = - list.skip(pageKey).take(_pageSize).toList(); // Get next batch of items + try { + final isLastPage = pageKey + _pageSize >= list.length; + final nextItems = list + .skip(pageKey) + .take(_pageSize) + .toList(); // Get next batch of items - if (isLastPage) { - pagingController.appendLastPage(nextItems); - } else { - final nextPageKey = pageKey + nextItems.length; - pagingController.appendPage(nextItems, nextPageKey); + if (isLastPage) { + pagingController.appendLastPage(nextItems); + } else { + final nextPageKey = pageKey + nextItems.length; + pagingController.appendPage(nextItems, nextPageKey); + } + } catch (error) { + pagingController.error = "Speakers not Available"; + } + } + + Future _showError(PagingStatus status) async { + if (status == PagingStatus.subsequentPageError) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: const Text( + 'Something went wrong while fetching', + ), + action: SnackBarAction( + label: 'Retry', + onPressed: () => pagingController.retryLastFailedRequest(), + ), + ), + ); + } + if (status == PagingStatus.noItemsFound) { + pagingController.error = "Speakers not available"; + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: const Text( + 'Speakers not available', + ), + action: SnackBarAction( + label: 'Retry', + onPressed: () => pagingController.retryLastFailedRequest(), + ), + ), + ); } } @@ -1599,46 +1637,29 @@ class _EventsListingScreenState extends State } } - return - // isTablet - // ? Container( - // margin: EdgeInsets.symmetric(vertical: 20.0), - // height: 200.0, - // child: Row( - // mainAxisAlignment: MainAxisAlignment.spaceEvenly, - // children: [ - // _topicCard("Top 3 topics", - // " 1. Hematologic Neoplasms \n 2. Antibodies, Bispecific \n 3. Multiple Myeloma"), - // _topicCard("Speakers with most sessions", - // " 1. James A. Davis \n 2. Sandra Cuellar \n 3. Allison Butts"), - // _topicCard("Sponsors", - // " 1. Amgen Inc \n 2. Bristol-Myers Squibb Company \n 3. Genmab A/S") - // ], - // )) - // : - Container( - height: MediaQuery.of(context).size.height, - color: AppColors.bgcolor, - padding: EdgeInsets.only(left: 8, right: 8), - child: SingleChildScrollView( - child: Expanded( - child: Column(children: [ - SizedBox( - height: 5, + return (topTopics.isEmpty && topSponsors.isEmpty && topSpeakers.isEmpty) + ? Center(child: Text("Details not available!")) + : Container( + height: MediaQuery.of(context).size.height, + color: AppColors.bgcolor, + padding: EdgeInsets.only(left: 8, right: 8), + child: SingleChildScrollView( + child: Expanded( + child: Column(spacing: 3, children: [ + topTopics.isEmpty + ? SizedBox.shrink() + : listViewTopicCard("Top 3 topics", topTopics, true), + topSpeakers.isEmpty + ? SizedBox.shrink() + : listViewTopicCard( + "Speakers with most sessions", topSpeakers, true), + topSponsors.isEmpty + ? SizedBox.shrink() + : listViewTopicCard("Sponsors", topSponsors, true) + ]), + ), ), - listViewTopicCard("Top 3 topics", topTopics, true), - SizedBox( - height: 3, - ), - listViewTopicCard("Speakers with most sessions", topSpeakers, true), - SizedBox( - height: 3, - ), - listViewTopicCard("Sponsors", topSponsors, true) - ]), - ), - ), - ); + ); } Widget _topicCard(String title, String content) { diff --git a/lib/view/home.dart b/lib/view/home.dart index 4f30def..ab5a57d 100644 --- a/lib/view/home.dart +++ b/lib/view/home.dart @@ -96,6 +96,7 @@ class _HomeScreenState extends State with TickerProviderStateMixin { pagingController.addPageRequestListener((pageKey) { _fetchPage(pageKey); }); + pagingController.addStatusListener(_showError); super.initState(); } @@ -184,6 +185,22 @@ class _HomeScreenState extends State with TickerProviderStateMixin { } } + Future _showError(PagingStatus status) async { + if (status == PagingStatus.subsequentPageError) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: const Text( + 'Something went wrong while fetching', + ), + action: SnackBarAction( + label: 'Retry', + onPressed: () => pagingController.retryLastFailedRequest(), + ), + ), + ); + } + } + init() async { await ApiCall().fetchApiConstants(); await Provider.of(context, listen: false) diff --git a/lib/view/insights.dart b/lib/view/insights.dart index 5b3c5a1..33318e3 100644 --- a/lib/view/insights.dart +++ b/lib/view/insights.dart @@ -87,6 +87,7 @@ class _EventsInsightsState extends State { child: SingleChildScrollView( child: Column( crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.center, children: [ Container( child: Wrap( @@ -139,7 +140,12 @@ class _EventsInsightsState extends State { color: AppColors.blueColor, ), ) - : _buildCharts(provider, widgets), + : (provider.affiliations.affiliationCount.isEmpty && + provider.specialtyList.isEmpty && + widgets.isEmpty && + widget.allSessionNotes.isEmpty) + ? Center(child: Text("Insights not available!")) + : _buildCharts(provider, widgets), widget.allSessionNotes.isNotEmpty ? labelWidget("Session Notes") : SizedBox.shrink(), diff --git a/lib/view/login.dart b/lib/view/login.dart index 4fdffaa..409b8e5 100644 --- a/lib/view/login.dart +++ b/lib/view/login.dart @@ -46,6 +46,7 @@ class _LoginScreenState extends State { late Future _login; late Future _logout; late Future _verification_code; + late Future _url; String platform = "android"; String? deviceId; final _mobileDeviceIdentifierPlugin = MobileDeviceIdentifier(); @@ -62,20 +63,16 @@ class _LoginScreenState extends State { platform = "ios"; } }); - // _username = _prefs.then((SharedPreferences prefs) { - // return prefs.getString('username') ?? ""; - // }); + _useremail = _prefs.then((SharedPreferences prefs) { emailTextController.text = prefs.getString('useremail') ?? ""; return prefs.getString('useremail') ?? ""; }); - // _domain = _prefs.then((SharedPreferences prefs) { - // return prefs.getString('domain') ?? ""; - // }); - // _key = _prefs.then((SharedPreferences prefs) { - // secretKeyTextConrtroller.text = prefs.getString('secretkey') ?? ""; - // return prefs.getString('secretkey') ?? ""; - // }); + _domain = _prefs.then((SharedPreferences prefs) { + domainTextConrtroller.text = prefs.getString('domain') ?? ""; + return prefs.getString('domain') ?? ""; + }); + _login = _prefs.then((SharedPreferences prefs) { return prefs.getBool('isloggedin') ?? false; }); @@ -270,13 +267,14 @@ class _LoginScreenState extends State { provider.loading = true; }); print("email:${emailTextController.text}"); + String domain = + "https://${domainTextConrtroller.text}.konectar.io/"; print("FIRST LOGIN"); if (!provider.showCodeField) { provider.email = emailTextController.text; // String encoded = // base64.encode(utf8.encode(deviceId)); - String domain = - "https://${domainTextConrtroller.text}.konectar.io/"; + var resp = await provider.verifyEmail(domain, emailTextController.text, deviceId!, platform); if (resp != null) { @@ -303,6 +301,7 @@ class _LoginScreenState extends State { emailTextController.text, secretKeyTextConrtroller.text, deviceId!, + domain, true) .then((value) { Navigator.of(context).pushReplacement( @@ -318,7 +317,6 @@ class _LoginScreenState extends State { SnackBarWidget.displaySnackBar( resp.message, context, error: true); - (); } provider.message = resp.message; @@ -341,6 +339,7 @@ class _LoginScreenState extends State { emailTextController.text, secretKeyTextConrtroller.text, deviceId!, + domain, true) .then((value) { Navigator.of(context).pushReplacement( @@ -378,8 +377,8 @@ class _LoginScreenState extends State { ); } - Future _saveprefs( - String token, String email, String key, String vcode, bool login) async { + Future _saveprefs(String token, String email, String key, String vcode, + String url, bool login) async { final SharedPreferences prefs = await _prefs; final String useremail = (prefs.getString('useremail') ?? ''); final String username = (prefs.getString('username') ?? ''); @@ -387,6 +386,7 @@ class _LoginScreenState extends State { final String secretkey = (prefs.getString('secretkey') ?? ''); final String verification_code = (prefs.getString('verfication_code') ?? ''); + final String urlstr = (prefs.getString('url') ?? ''); final bool isloggedin = (prefs.getBool('isloggedin') ?? false); final bool isloggedout = (prefs.getBool('isloggedout') ?? false); setState(() { @@ -404,6 +404,9 @@ class _LoginScreenState extends State { prefs.setString('deviceid', vcode).then((bool success) { return verification_code; }); + _url = prefs.setString('url', url).then((bool success) { + return urlstr; + }); _login = prefs.setBool('isloggedin', login).then((bool success) { return isloggedin; }); diff --git a/lib/view/login_components/care_view.dart b/lib/view/login_components/care_view.dart index 6f82d83..506c1cc 100644 --- a/lib/view/login_components/care_view.dart +++ b/lib/view/login_components/care_view.dart @@ -82,20 +82,20 @@ class CareView extends StatelessWidget { // // width: MediaQuery.of(context).size.width, // // height: MediaQuery.of(context).size.height, // ), - Align( - alignment: Alignment.centerRight, - child: Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.only( - bottomLeft: Radius.circular(100), - topLeft: Radius.circular(100)), - color: const Color.fromARGB(255, 167, 203, 234), - shape: BoxShape.rectangle, - ), - height: MediaQuery.of(context).size.height / 2, - width: MediaQuery.of(context).size.width / 4, - ), - ), + // Align( + // alignment: Alignment.centerRight, + // child: Container( + // decoration: BoxDecoration( + // borderRadius: BorderRadius.only( + // bottomLeft: Radius.circular(100), + // topLeft: Radius.circular(100)), + // color: const Color.fromARGB(255, 167, 203, 234), + // shape: BoxShape.rectangle, + // ), + // height: MediaQuery.of(context).size.height / 2, + // width: MediaQuery.of(context).size.width / 4, + // ), + // ), Container( padding: const EdgeInsets.only(bottom: 100), child: Column( diff --git a/lib/widgets/home_drawer.dart b/lib/widgets/home_drawer.dart index e7d7970..34b65f3 100644 --- a/lib/widgets/home_drawer.dart +++ b/lib/widgets/home_drawer.dart @@ -6,6 +6,7 @@ import 'package:konectar_events/utils/sessionmanager.dart'; import 'package:konectar_events/view/login.dart'; import 'package:konectar_events/viewmodel/hive_repository.dart'; import 'package:konectar_events/viewmodel/loginprovider.dart'; +import 'package:konectar_events/widgets/snackbar.dart'; import 'package:provider/provider.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -335,16 +336,26 @@ class _HomeDrawerState extends State { void onTapped() async { print("device id : ${await _deviceid}"); - final resp = await ApiCall().logout(await _useremail, await _deviceid); + dynamic resp = await ApiCall().logout(await _useremail, await _deviceid); print("resp:$resp"); - await SessionManager().logoutSession(false).then((value) { - Navigator.of(context).popUntil((route) => route.isFirst); - // Navigator.of(context, rootNavigator: true).pushReplacementNamed("/"); - Navigator.pushReplacement( + if (resp.status == 1200) { + SnackBarWidget.displaySnackBar( + resp.message, context, - MaterialPageRoute(builder: (context) => LoginScreen()), ); - }); + await SessionManager().logoutSession(false).then((value) { + Navigator.of(context).popUntil((route) => route.isFirst); + // Navigator.of(context, rootNavigator: true).pushReplacementNamed("/"); + Navigator.pushReplacement( + context, + MaterialPageRoute(builder: (context) => LoginScreen()), + ); + }); + } else { + SnackBarWidget.displaySnackBar( + "Something went wrong..Try Again!", context, + error: true); + } } Widget inkwell(DrawerList listData) { -- 2.34.1