diff --git a/lib/ui/landing/dashboard_screen.dart b/lib/ui/landing/dashboard_screen.dart index 22768e6..4172cc7 100644 --- a/lib/ui/landing/dashboard_screen.dart +++ b/lib/ui/landing/dashboard_screen.dart @@ -1,7 +1,7 @@ import 'dart:async'; import 'dart:io'; - import 'dart:ui' as ui; + import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter_countdown_timer/flutter_countdown_timer.dart'; @@ -323,12 +323,104 @@ class _DashboardScreenState extends State { ], ), ], - ).paddingOnly(left: 21, right: 21, top: 7), - context.watch().isLoading - ? const MarathonBannerShimmer().paddingAll(20) - : MarathonBanner(isMarathonUpcoming: context.watch().isUpComingMarathon).paddingAll(20), - ServicesWidget(), - 8.height, + ).paddingOnly(left: 21, right: 21, top: 7, bottom: 21), + Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + LocaleKeys.offers.tr().toText12(), + Row( + children: [ + LocaleKeys.discounts.tr().toText24(isBold: true), + 6.width, + Container( + padding: const EdgeInsets.only(left: 8, right: 8), + decoration: BoxDecoration( + color: MyColors.yellowColor, + borderRadius: BorderRadius.circular(10), + ), + child: LocaleKeys.newString.tr().toText10(isBold: true)), + ], + ), + ], + ), + ), + LocaleKeys.viewAllOffers.tr().toText12(isUnderLine: true).onPress(() { + Navigator.pushNamed(context, AppRoutes.offersAndDiscounts); + }) + ], + ).paddingOnly(left: 21, right: 21), + Consumer( + builder: (BuildContext context, DashboardProviderModel model, Widget? child) { + return SizedBox( + height: 103 + 33, + child: ListView.separated( + shrinkWrap: true, + physics: const BouncingScrollPhysics(), + padding: const EdgeInsets.only(left: 21, right: 21, top: 13), + scrollDirection: Axis.horizontal, + itemBuilder: (BuildContext cxt, int index) { + return model.isOffersLoading + ? const OffersShimmerWidget() + : InkWell( + onTap: () { + navigateToDetails(data.getOffersList[index]); + }, + child: SizedBox( + width: 73, + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Container( + width: 73, + height: 73, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: const BorderRadius.all( + Radius.circular(100), + ), + border: Border.all(color: MyColors.lightGreyE3Color, width: 1), + ), + child: ClipRRect( + borderRadius: const BorderRadius.all( + Radius.circular(50), + ), + child: Hero( + tag: "ItemImage" + data.getOffersList[index].rowID!, + transitionOnUserGestures: true, + child: Image.network( + data.getOffersList[index].bannerImage!, + fit: BoxFit.contain, + ), + ), + ), + ), + 4.height, + Expanded( + child: AppState().isArabic(context) + ? data.getOffersList[index].titleAR!.toText12(isCenter: true, maxLine: 1) + : data.getOffersList[index].title!.toText12(isCenter: true, maxLine: 1), + ), + ], + ), + ), + ); + }, + separatorBuilder: (BuildContext cxt, int index) => 8.width, + itemCount: 6), + ); + }, + ), + ], + ), Container( width: double.infinity, padding: const EdgeInsets.only(top: 31), @@ -339,101 +431,14 @@ class _DashboardScreenState extends State { ), child: Column( mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.start, children: [ - Row( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - LocaleKeys.offers.tr().toText12(), - Row( - children: [ - LocaleKeys.discounts.tr().toText24(isBold: true), - 6.width, - Container( - padding: const EdgeInsets.only(left: 8, right: 8), - decoration: BoxDecoration( - color: MyColors.yellowColor, - borderRadius: BorderRadius.circular(10), - ), - child: LocaleKeys.newString.tr().toText10(isBold: true)), - ], - ), - ], - ), - ), - LocaleKeys.viewAllOffers.tr().toText12(isUnderLine: true).onPress(() { - Navigator.pushNamed(context, AppRoutes.offersAndDiscounts); - }) - ], - ).paddingOnly(left: 21, right: 21), - Consumer( - builder: (BuildContext context, DashboardProviderModel model, Widget? child) { - return SizedBox( - height: 103 + 33, - child: ListView.separated( - shrinkWrap: true, - physics: const BouncingScrollPhysics(), - padding: const EdgeInsets.only(left: 21, right: 21, top: 13), - scrollDirection: Axis.horizontal, - itemBuilder: (BuildContext cxt, int index) { - return model.isOffersLoading - ? const OffersShimmerWidget() - : InkWell( - onTap: () { - navigateToDetails(data.getOffersList[index]); - }, - child: SizedBox( - width: 73, - child: Column( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Container( - width: 73, - height: 73, - decoration: BoxDecoration( - borderRadius: const BorderRadius.all( - Radius.circular(100), - ), - border: Border.all(color: MyColors.lightGreyE3Color, width: 1), - ), - child: ClipRRect( - borderRadius: const BorderRadius.all( - Radius.circular(50), - ), - child: Hero( - tag: "ItemImage" + data.getOffersList[index].rowID!, - transitionOnUserGestures: true, - child: Image.network( - data.getOffersList[index].bannerImage!, - fit: BoxFit.contain, - ), - ), - ), - ), - 4.height, - Expanded( - child: AppState().isArabic(context) - ? data.getOffersList[index].titleAR!.toText12(isCenter: true, maxLine: 1) - : data.getOffersList[index].title!.toText12(isCenter: true, maxLine: 1), - ), - ], - ), - ), - ); - }, - separatorBuilder: (BuildContext cxt, int index) => 8.width, - itemCount: 6), - ); - }, - ), + ServicesWidget(), + context.watch().isLoading + ? const MarathonBannerShimmer().paddingAll(20) + : MarathonBanner(isMarathonUpcoming: context.watch().isUpComingMarathon).paddingOnly(left: 21, right: 21, bottom: 21, top: 8), ], ), - ) + ), ], ), ), diff --git a/lib/ui/login/login_screen.dart b/lib/ui/login/login_screen.dart index 04c3077..3cc74b1 100644 --- a/lib/ui/login/login_screen.dart +++ b/lib/ui/login/login_screen.dart @@ -95,6 +95,8 @@ class _LoginScreenState extends State { firebaseToken = await _firebaseMessaging.getToken(); loginInfo = await LoginApiClient().getMobileLoginInfoNEW(firebaseToken ?? "", Platform.isAndroid ? "android" : "ios"); if (loginInfo == null) { + await checkPrefs(); + _autoLogin = false; Utils.hideLoading(context); return; } else { diff --git a/lib/ui/work_list/work_list_screen.dart b/lib/ui/work_list/work_list_screen.dart index 69fb7f3..9b7fbe5 100644 --- a/lib/ui/work_list/work_list_screen.dart +++ b/lib/ui/work_list/work_list_screen.dart @@ -81,7 +81,7 @@ class _WorkListScreenState extends State { value: 0, name: 'COC', fullName: LocaleKeys.itemCreation.tr(), active: false, color: [Color(0xff787299), Color(0xff1AB170)], icon: "assets/images/miss_swipe.svg", key: 'COC', disable: true) ]; - int workListItemIndex = 0; + int? workListItemIndex; List? workList; int pageNumber = 1; @@ -99,7 +99,7 @@ class _WorkListScreenState extends State { super.initState(); providerData = Provider.of(context, listen: false); calculateCounter(); - getWorkList(); + if (workListItemIndex != null) getWorkList(); } void calculateCounter() { @@ -115,11 +115,17 @@ class _WorkListScreenState extends State { } } }); + workListItemTypes.removeWhere((element) => element.value == 0); + if (workListItemTypes.isNotEmpty) { + workListItemIndex = 0; + } else { + workListItemIndex = null; + } } void verifyWorkListCounter() { workListItemTypes.forEach((workListElement) { - if (workListElement.key == "ITG" && workListItemTypes[workListItemIndex].key == "ITG") { + if (workListElement.key == "ITG" && workListItemTypes[workListItemIndex!].key == "ITG") { workListElement.value = providerData.itgFormsModel?.totalCount ?? 0; if ((AppState().requestAllList?.length ?? 0) != workListElement.value) { workListElement.value = AppState().requestAllList?.length ?? 0; @@ -132,7 +138,7 @@ class _WorkListScreenState extends State { workListElement.value = providerData.cocFinalCount; } else { providerData.getOpenNotificationsList?.forEach((element) { - if ((element.itemType == workListItemTypes[workListItemIndex].key) && element.itemType == workListElement.key) { + if ((element.itemType == workListItemTypes[workListItemIndex!].key) && element.itemType == workListElement.key) { if ((AppState().workList?.length ?? 0) != (element.openNtfNumber ?? 0)) { workListElement.value = AppState().workList?.length ?? 0; providerData.workListCounter = providerData.workListCounter - ((element.openNtfNumber ?? 0) - (AppState().workList?.length ?? 0)); @@ -162,7 +168,7 @@ class _WorkListScreenState extends State { Future getWorkList({bool showLoading = true}) async { try { if (showLoading) Utils.showLoading(context); - if (workListItemTypes[workListItemIndex].key == "ITG") { + if (workListItemTypes[workListItemIndex!].key == "ITG") { itgFormsModel = await WorkListApiClient().getITGTaskCountRequestType(); List requestAllList = []; for (int i = 0; i < (itgFormsModel?.requestType!.length ?? 0); i++) { @@ -178,7 +184,7 @@ class _WorkListScreenState extends State { } } else { itgRequestTypeIndex = null; - workList = await WorkListApiClient().getWorkList(pageNumber, workListItemTypes[workListItemIndex].key, pNotificationType.toString()); + workList = await WorkListApiClient().getWorkList(pageNumber, workListItemTypes[workListItemIndex!].key, pNotificationType.toString()); AppState().setWorkList = workList; } if (showLoading) Utils.hideLoading(context); @@ -216,127 +222,129 @@ class _WorkListScreenState extends State { return Scaffold( backgroundColor: Colors.white, appBar: AppBarWidget(context, title: LocaleKeys.workList.tr(), showWorkListSettingButton: true), - body: SizedBox( - width: double.infinity, - height: double.infinity, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - SizedBox( - height: 40, - child: ListView.separated( - controller: _controller, - itemBuilder: (context, index) { - return Container( - padding: const EdgeInsets.only(left: 21, right: 21, top: 8, bottom: 8), - alignment: Alignment.center, - decoration: BoxDecoration(borderRadius: BorderRadius.circular(6), color: workListItemIndex == index ? MyColors.darkIconColor : MyColors.lightGreyEAColor), - child: ("${workListItemTypes[index].name} ${workListItemTypes[index].value > 0 ? "(${workListItemTypes[index].value})" : ""}") - .toText12(color: workListItemIndex == index ? MyColors.white : MyColors.black), - ).onPress(() { - if (pNotificationType != 1) { - pNotificationType = 1; - } - if (workListItemIndex != index && !workListItemTypes[index].disable) { - workListItemIndex = index; - if (workListItemTypes[index].value == 0) { - workList = []; - itgRequestTypeIndex = null; - } else { - workList = null; - } - setState(() {}); - if (workListItemTypes[index].value > 0) { - getWorkList(); - } - } - }); - }, - separatorBuilder: (context, index) => 8.width, - shrinkWrap: true, - itemCount: workListItemTypes.length, - scrollDirection: Axis.horizontal, - padding: const EdgeInsets.only(left: 21, right: 21), + body: workListItemIndex == null + ? Utils.getNoDataWidget(context) + : SizedBox( + width: double.infinity, + height: double.infinity, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SizedBox( + height: 40, + child: ListView.separated( + controller: _controller, + itemBuilder: (context, index) { + return Container( + padding: const EdgeInsets.only(left: 21, right: 21, top: 8, bottom: 8), + alignment: Alignment.center, + decoration: BoxDecoration(borderRadius: BorderRadius.circular(6), color: workListItemIndex == index ? MyColors.darkIconColor : MyColors.lightGreyEAColor), + child: ("${workListItemTypes[index].name} ${workListItemTypes[index].value > 0 ? "(${workListItemTypes[index].value})" : ""}") + .toText12(color: workListItemIndex == index ? MyColors.white : MyColors.black), + ).onPress(() { + if (pNotificationType != 1) { + pNotificationType = 1; + } + if (workListItemIndex != index && !workListItemTypes[index].disable) { + workListItemIndex = index; + if (workListItemTypes[index].value == 0) { + workList = []; + itgRequestTypeIndex = null; + } else { + workList = null; + } + setState(() {}); + if (workListItemTypes[index].value > 0) { + getWorkList(); + } + } + }); + }, + separatorBuilder: (context, index) => 8.width, + shrinkWrap: true, + itemCount: workListItemTypes.length, + scrollDirection: Axis.horizontal, + padding: const EdgeInsets.only(left: 21, right: 21), + ), + ).paddingOnly(top: 21, bottom: 21), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + workListItemTypes[workListItemIndex!].fullName.toSectionHeading().paddingOnly(left: 21, right: 21), + LocaleKeys.advancedSearch.tr().toText14(isUnderLine: true, color: MyColors.textMixColor).onPress(() { + openBottomSheet(context); + }).paddingOnly(left: 21, right: 21) + ], + ), + SmartRefresher( + enablePullDown: true, + enablePullUp: false, + header: const MaterialClassicHeader( + color: MyColors.gradiantEndColor, + ), + controller: _refreshController, + onRefresh: _onRefresh, + child: SingleChildScrollView( + physics: const BouncingScrollPhysics(), + child: itgRequestTypeIndex != null + ? Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + // todo this is commented for temporary purpose, have issue when selecting any itg category and click any item showing wrong details + // SizedBox( + // height: 40, + // child: ListView.separated( + // itemBuilder: (context, index) { + // RequestType type = itgFormsModel!.requestType![index]; + // return Container( + // padding: const EdgeInsets.only(left: 21, right: 21, top: 8, bottom: 8), + // alignment: Alignment.center, + // decoration: BoxDecoration(borderRadius: BorderRadius.circular(30), color: itgRequestTypeIndex == index ? MyColors.darkIconColor : MyColors.lightGreyEAColor), + // child: ("${type.requestTypeName}").toText12(color: itgRequestTypeIndex == index ? MyColors.white : MyColors.black), + // ).onPress(() { + // if (itgRequestTypeIndex != index) { + // itgRequestTypeIndex = index; + // setState(() {}); + // } + // }); + // }, + // separatorBuilder: (context, index) => 8.width, + // shrinkWrap: true, + // itemCount: itgFormsModel?.requestType?.length ?? 0, + // scrollDirection: Axis.horizontal, + // padding: const EdgeInsets.only(left: 21, right: 21), + // ), + // ).paddingOnly(top: 16, bottom: 16), + ListView.separated( + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + itemBuilder: (context, index) { + return itgRowItem(workListItemTypes[workListItemIndex!], itgFormsModel!.requestType![itgRequestTypeIndex!].requestDetails![index], index); + }, + separatorBuilder: (context, index) => 12.height, + itemCount: itgFormsModel!.requestType![itgRequestTypeIndex!].requestDetails?.length ?? 0, + padding: const EdgeInsets.all(21), + ), + ], + ) + : workList != null + ? ((workList!).isEmpty + ? Utils.getNoDataWidget(context).paddingOnly(top: 100) + : ListView.separated( + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + itemBuilder: (context, index) { + return rowItem(workListItemTypes[workListItemIndex!], workList![index], index); + }, + separatorBuilder: (context, index) => 12.height, + itemCount: workList?.length ?? 0, + padding: const EdgeInsets.all(21), + )) + : const SizedBox(), + )).expanded, + ], ), - ).paddingOnly(top: 21, bottom: 21), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - workListItemTypes[workListItemIndex].fullName.toSectionHeading().paddingOnly(left: 21, right: 21), - LocaleKeys.advancedSearch.tr().toText14(isUnderLine: true, color: MyColors.textMixColor).onPress(() { - openBottomSheet(context); - }).paddingOnly(left: 21, right: 21) - ], ), - SmartRefresher( - enablePullDown: true, - enablePullUp: false, - header: const MaterialClassicHeader( - color: MyColors.gradiantEndColor, - ), - controller: _refreshController, - onRefresh: _onRefresh, - child: SingleChildScrollView( - physics: const BouncingScrollPhysics(), - child: itgRequestTypeIndex != null - ? Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - // todo this is commented for temporary purpose, have issue when selecting any itg category and click any item showing wrong details - // SizedBox( - // height: 40, - // child: ListView.separated( - // itemBuilder: (context, index) { - // RequestType type = itgFormsModel!.requestType![index]; - // return Container( - // padding: const EdgeInsets.only(left: 21, right: 21, top: 8, bottom: 8), - // alignment: Alignment.center, - // decoration: BoxDecoration(borderRadius: BorderRadius.circular(30), color: itgRequestTypeIndex == index ? MyColors.darkIconColor : MyColors.lightGreyEAColor), - // child: ("${type.requestTypeName}").toText12(color: itgRequestTypeIndex == index ? MyColors.white : MyColors.black), - // ).onPress(() { - // if (itgRequestTypeIndex != index) { - // itgRequestTypeIndex = index; - // setState(() {}); - // } - // }); - // }, - // separatorBuilder: (context, index) => 8.width, - // shrinkWrap: true, - // itemCount: itgFormsModel?.requestType?.length ?? 0, - // scrollDirection: Axis.horizontal, - // padding: const EdgeInsets.only(left: 21, right: 21), - // ), - // ).paddingOnly(top: 16, bottom: 16), - ListView.separated( - shrinkWrap: true, - physics: const NeverScrollableScrollPhysics(), - itemBuilder: (context, index) { - return itgRowItem(workListItemTypes[workListItemIndex], itgFormsModel!.requestType![itgRequestTypeIndex!].requestDetails![index], index); - }, - separatorBuilder: (context, index) => 12.height, - itemCount: itgFormsModel!.requestType![itgRequestTypeIndex!].requestDetails?.length ?? 0, - padding: const EdgeInsets.all(21), - ), - ], - ) - : workList != null - ? ((workList!).isEmpty - ? Utils.getNoDataWidget(context).paddingOnly(top: 100) - : ListView.separated( - shrinkWrap: true, - physics: const NeverScrollableScrollPhysics(), - itemBuilder: (context, index) { - return rowItem(workListItemTypes[workListItemIndex], workList![index], index); - }, - separatorBuilder: (context, index) => 12.height, - itemCount: workList?.length ?? 0, - padding: const EdgeInsets.all(21), - )) - : const SizedBox(), - )).expanded, - ], - ), - ), ); } @@ -350,7 +358,10 @@ class _WorkListScreenState extends State { if (shouldReloadData.toString() == "delegate_reload") { providerData.itgFormsModel!.totalCount = providerData.itgFormsModel!.totalCount! - 1; calculateCounter(); - getWorkList(); + setState(() {}); + if (workListItemIndex != null) { + getWorkList(); + } } // workList!.remove(data); // AppState().setWorkList = workList;