Pull to refresh, Items for Sale & Offers n Discounts fixes

merge-requests/8/head
haroon amjad 3 years ago
parent 4c1927bee5
commit 866bb8a29e

@ -72,6 +72,33 @@ class DashboardProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
return true;
}
void initProvider() {
isAttendanceTrackingLoading = true;
endTime = 0;
isTimeRemainingInSeconds = 0;
progress = 0.0;
attendanceTracking = null;
isWorkListLoading = true;
workListCounter = 0;
isMissingSwipeLoading = true;
missingSwipeCounter = 0;
isLeaveTicketBalanceLoading = true;
accrualList = null;
leaveBalanceAccrual = null;
ticketBalance = 0;
isServicesMenusLoading = true;
homeMenus = null;
getMenuEntriesList = null;
isOffersLoading = true;
getOffersList = [];
notifyListeners();
}
int calculateSeconds(String time) {
int hour = int.parse(time.split(":")[0]);
int mints = int.parse(time.split(":")[1]);
@ -81,12 +108,6 @@ class DashboardProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
void update(context) {
fetchAttendanceTracking(context);
// isAttendanceTrackingLoading = !isAttendanceTrackingLoading;
// isWorkListLoading = !isWorkListLoading;
// attendanceTracking?.pSwipeIn = "a";
// isTimeRemainingInSeconds = calculateSeconds("00:10:30");
// endTime = DateTime.now().millisecondsSinceEpoch + Duration(seconds: isTimeRemainingInSeconds).inMilliseconds;
// notifyListeners();
}
ItgFormsModel? itgFormsModel;

@ -23,6 +23,7 @@ import 'package:mohem_flutter_app/widgets/mark_attendance_widget.dart';
import 'package:mohem_flutter_app/widgets/shimmer/dashboard_shimmer_widget.dart';
import 'package:mohem_flutter_app/widgets/shimmer/offers_shimmer_widget.dart';
import 'package:provider/provider.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
class DashboardScreen extends StatefulWidget {
DashboardScreen({Key? key}) : super(key: key);
@ -37,12 +38,24 @@ class _DashboardScreenState extends State<DashboardScreen> {
late DashboardProviderModel data;
final GlobalKey<ScaffoldState> _scaffoldState = GlobalKey();
final RefreshController _refreshController = RefreshController(initialRefresh: false);
int currentIndex = 0;
@override
void initState() {
super.initState();
data = Provider.of<DashboardProviderModel>(context, listen: false);
_onRefresh();
}
@override
void dispose() {
super.dispose();
}
void _onRefresh() async {
data.initProvider();
data.fetchListMenu();
data.fetchAttendanceTracking(context);
data.fetchWorkListCounter(context);
@ -50,11 +63,7 @@ class _DashboardScreenState extends State<DashboardScreen> {
data.fetchLeaveTicketBalance(context, DateTime.now());
data.fetchMenuEntries();
data.getCategoryOffersListAPI(context);
}
@override
void dispose() {
super.dispose();
_refreshController.refreshCompleted();
}
@override
@ -122,236 +131,243 @@ class _DashboardScreenState extends State<DashboardScreen> {
],
).paddingOnly(left: 21, right: 21, top: 48, bottom: 7),
Expanded(
child: SingleChildScrollView(
child: Column(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
LocaleKeys.goodMorning.tr().toText14(color: MyColors.grey77Color),
(AppState().memberInformationList!.eMPLOYEENAME ?? "").toText24(isBold: true),
16.height,
Row(
children: [
Expanded(
child: AspectRatio(
aspectRatio: 159 / 159,
child: Consumer<DashboardProviderModel>(
builder: (context, model, child) {
return (model.isAttendanceTrackingLoading
? GetAttendanceTrackingShimmer()
: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
gradient: const LinearGradient(transform: GradientRotation(.46), begin: Alignment.topRight, end: Alignment.bottomLeft, colors: [
MyColors.gradiantEndColor,
MyColors.gradiantStartColor,
]),
),
child: Stack(
alignment: Alignment.center,
children: [
if (model.isTimeRemainingInSeconds == 0) SvgPicture.asset("assets/images/thumb.svg"),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
LocaleKeys.markAttendance.tr().toText14(color: Colors.white, isBold: true),
if (model.isTimeRemainingInSeconds == 0) "01-02-2022".toText12(color: Colors.white),
if (model.isTimeRemainingInSeconds != 0)
Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
9.height,
CountdownTimer(
endTime: model.endTime,
onEnd: null,
endWidget: "00:00:00".toText14(color: Colors.white, isBold: true),
textStyle: TextStyle(color: Colors.white, fontSize: 14, letterSpacing: -0.48, fontWeight: FontWeight.bold),
),
LocaleKeys.timeLeftToday.tr().toText12(color: Colors.white),
9.height,
ClipRRect(
borderRadius: BorderRadius.all(
Radius.circular(20),
),
child: LinearProgressIndicator(
value: model.progress,
minHeight: 8,
valueColor: const AlwaysStoppedAnimation<Color>(Colors.white),
backgroundColor: const Color(0xff196D73),
),
),
],
),
],
).paddingOnly(top: 12, right: 15, left: 12),
),
Row(
child: SmartRefresher(
enablePullDown: true,
enablePullUp: false,
header: const MaterialClassicHeader(color: MyColors.gradiantEndColor,),
controller: _refreshController,
onRefresh: _onRefresh,
child: SingleChildScrollView(
child: Column(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
LocaleKeys.goodMorning.tr().toText14(color: MyColors.grey77Color),
(AppState().memberInformationList!.eMPLOYEENAME ?? "").toText24(isBold: true),
16.height,
Row(
children: [
Expanded(
child: AspectRatio(
aspectRatio: 159 / 159,
child: Consumer<DashboardProviderModel>(
builder: (context, model, child) {
return (model.isAttendanceTrackingLoading
? GetAttendanceTrackingShimmer()
: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
gradient: const LinearGradient(transform: GradientRotation(.46), begin: Alignment.topRight, end: Alignment.bottomLeft, colors: [
MyColors.gradiantEndColor,
MyColors.gradiantStartColor,
]),
),
child: Stack(
alignment: Alignment.center,
children: [
if (model.isTimeRemainingInSeconds == 0) SvgPicture.asset("assets/images/thumb.svg"),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
LocaleKeys.markAttendance.tr().toText14(color: Colors.white, isBold: true),
if (model.isTimeRemainingInSeconds == 0) "01-02-2022".toText12(color: Colors.white),
if (model.isTimeRemainingInSeconds != 0)
Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
LocaleKeys.checkIn.tr().toText12(color: Colors.white),
(model.attendanceTracking!.pSwipeIn == null ? "--:--" : model.attendanceTracking!.pSwipeIn)
.toString()
.toText14(color: Colors.white, isBold: true),
4.height,
],
).paddingOnly(left: 12),
9.height,
CountdownTimer(
endTime: model.endTime,
onEnd: null,
endWidget: "00:00:00".toText14(color: Colors.white, isBold: true),
textStyle: TextStyle(color: Colors.white, fontSize: 14, letterSpacing: -0.48, fontWeight: FontWeight.bold),
),
Container(
width: 45,
height: 45,
padding: const EdgeInsets.only(left: 14, right: 14),
decoration: const BoxDecoration(
color: Color(0xff259EA4),
borderRadius: BorderRadius.only(
bottomRight: Radius.circular(15),
),
LocaleKeys.timeLeftToday.tr().toText12(color: Colors.white),
9.height,
ClipRRect(
borderRadius: BorderRadius.all(
Radius.circular(20),
),
child: SvgPicture.asset(model.isTimeRemainingInSeconds == 0 ? "assets/images/play.svg" : "assets/images/stop.svg"),
).onPress(() {
showMyBottomSheet(context, child: MarkAttendanceWidget(model));
}),
child: LinearProgressIndicator(
value: model.progress,
minHeight: 8,
valueColor: const AlwaysStoppedAnimation<Color>(Colors.white),
backgroundColor: const Color(0xff196D73),
),
),
],
),
],
],
).paddingOnly(top: 12, right: 15, left: 12),
),
Row(
children: [
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
LocaleKeys.checkIn.tr().toText12(color: Colors.white),
(model.attendanceTracking!.pSwipeIn == null ? "--:--" : model.attendanceTracking!.pSwipeIn)
.toString()
.toText14(color: Colors.white, isBold: true),
4.height,
],
).paddingOnly(left: 12),
),
Container(
width: 45,
height: 45,
padding: const EdgeInsets.only(left: 14, right: 14),
decoration: const BoxDecoration(
color: Color(0xff259EA4),
borderRadius: BorderRadius.only(
bottomRight: Radius.circular(15),
),
),
child: SvgPicture.asset(model.isTimeRemainingInSeconds == 0 ? "assets/images/play.svg" : "assets/images/stop.svg"),
).onPress(() {
showMyBottomSheet(context, child: MarkAttendanceWidget(model));
}),
],
),
).onPress(
() {
Navigator.pushNamed(context, AppRoutes.todayAttendance);
},
))
.animatedSwither();
},
],
),
],
),
).onPress(
() {
Navigator.pushNamed(context, AppRoutes.todayAttendance);
},
))
.animatedSwither();
},
),
),
),
),
9.width,
Expanded(
child: MenusWidget(),
),
],
),
],
).paddingOnly(left: 21, right: 21, top: 7),
ServicesWidget(),
// 8.height,
Container(
width: double.infinity,
padding: const EdgeInsets.only(top: 31),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: const BorderRadius.only(topRight: Radius.circular(50), topLeft: Radius.circular(50)),
border: Border.all(color: MyColors.lightGreyEDColor, width: 1),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
9.width,
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)),
],
),
],
),
child: MenusWidget(),
),
LocaleKeys.viewAllOffers.tr().toText12(isUnderLine: true).onPress(() {
Navigator.pushNamed(context, AppRoutes.offersAndDiscounts);
})
],
).paddingOnly(left: 21, right: 21),
Consumer<DashboardProviderModel>(
builder: (context, model, 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: (cxt, 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,
),
),
),
),
],
).paddingOnly(left: 21, right: 21, top: 7),
ServicesWidget(),
// 8.height,
Container(
width: double.infinity,
padding: const EdgeInsets.only(top: 31),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: const BorderRadius.only(topRight: Radius.circular(50), topLeft: Radius.circular(50)),
border: Border.all(color: MyColors.lightGreyEDColor, width: 1),
),
child: Column(
mainAxisSize: MainAxisSize.min,
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<DashboardProviderModel>(
builder: (context, model, 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: (cxt, 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),
),
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),
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,
),
),
),
),
),
);
},
separatorBuilder: (cxt, index) => 8.width,
itemCount: 6),
);
},
),
],
),
)
],
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: (cxt, index) => 8.width,
itemCount: 6),
);
},
),
],
),
)
],
),
),
),
)

@ -22,10 +22,10 @@ class ServicesWidget extends StatelessWidget {
"assets/images/monthly_attendance.svg",
"assets/images/ticket_request.svg",
"assets/images/ticket_request.svg",
"assets/images/dynamic_screens.svg",
"assets/images/dynamic_screens.svg",
"assets/images/dynamic_screens.svg",
"assets/images/dynamic_screens.svg"
"assets/images/ticket_request.svg",
"assets/images/ticket_request.svg",
"assets/images/ticket_request.svg",
"assets/images/ticket_request.svg"
];
return Consumer<DashboardProviderModel>(

@ -25,6 +25,7 @@ class _ItemsForSaleFragmentState extends State<ItemsForSaleFragment> {
List<GetSaleCategoriesList> getSaleCategoriesList = [];
List<GetItemsForSaleList> getItemsForSaleList = [];
List<GetItemsForSaleList> _foundItemsForSaleList = [];
ScrollController gridScrollController = ScrollController();
int currentPageNo = 1;
@ -61,20 +62,10 @@ class _ItemsForSaleFragmentState extends State<ItemsForSaleFragment> {
isInputTypeNum: false,
isReadOnly: false,
onChange: (String value) {
// _runFilter(value);
_runFilter(value);
},
).paddingOnly(left: 21, right: 21, top: 21),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
LocaleKeys.browseCategories.tr().toText17(),
// todo @haroon define the purpose of this icon button
IconButton(
icon: const Icon(Icons.filter_alt_sharp, color: MyColors.darkIconColor, size: 28.0),
onPressed: () => Navigator.pop(context),
),
],
).paddingOnly(left: 21, right: 21),
LocaleKeys.browseCategories.tr().toText17().paddingOnly(left: 21, right: 21, top: 21),
SizedBox(
height: 105.0,
child: getSaleCategoriesList.isNotEmpty
@ -132,10 +123,22 @@ class _ItemsForSaleFragmentState extends State<ItemsForSaleFragment> {
);
}
void _runFilter(String enteredKeyword) {
List<GetItemsForSaleList> results = [];
if (enteredKeyword.isEmpty) {
results = getItemsForSaleList;
} else {
results = getItemsForSaleList.where((offer) => offer.title!.toLowerCase().contains(enteredKeyword.toLowerCase())).toList();
}
setState(() {
_foundItemsForSaleList = results;
});
}
List<Widget> getItemsForSaleWidgets() {
List<Widget> itemsList = [];
getItemsForSaleList.forEach((element) {
_foundItemsForSaleList.forEach((element) {
itemsList.add(getItemCard(element));
});
@ -200,6 +203,7 @@ class _ItemsForSaleFragmentState extends State<ItemsForSaleFragment> {
getItemsForSaleListLocal.clear();
getItemsForSaleListLocal = await ItemsForSaleApiClient().getItemsForSale(itgPageNo, itgCategoryID);
getItemsForSaleList.addAll(getItemsForSaleListLocal);
_foundItemsForSaleList = getItemsForSaleList;
Utils.hideLoading(context);
setState(() {});
} catch (ex) {

@ -25,6 +25,7 @@ class OffersAndDiscountsHome extends StatefulWidget {
class _OffersAndDiscountsHomeState extends State<OffersAndDiscountsHome> {
List<GetCategoriesList> getCategoriesList = [];
List<OffersListModel> getOffersList = [];
List<OffersListModel> _foundOffersList = [];
int currentCategoryID = 0;
@ -54,18 +55,10 @@ class _OffersAndDiscountsHomeState extends State<OffersAndDiscountsHome> {
isInputTypeNum: false,
isReadOnly: false,
onChange: (String value) {
// _runFilter(value);
_runFilter(value);
},
).paddingOnly(left: 21, right: 21, top: 21),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
LocaleKeys.browseCategories.tr().toText17(),
const Icon(Icons.filter_alt_sharp, color: MyColors.darkIconColor, size: 28.0).onPress(() {
Navigator.pop(context);
}),
],
).paddingOnly(left: 21, right: 21, top: 21),
LocaleKeys.browseCategories.tr().toText17().paddingOnly(left: 21, right: 21, top: 21),
SizedBox(
height: 110.0,
child: getCategoriesList.isNotEmpty
@ -81,6 +74,7 @@ class _OffersAndDiscountsHomeState extends State<OffersAndDiscountsHome> {
onTap: () {
setState(() {
currentCategoryID = getCategoriesList[index].id!;
getCategoryOffersListAPI();
// getItemsForSaleList.clear();
// currentPageNo = 1;
// getItemsForSale(currentPageNo, currentCategoryID);
@ -146,7 +140,7 @@ class _OffersAndDiscountsHomeState extends State<OffersAndDiscountsHome> {
List<Widget> getItemsForSaleWidgets() {
List<Widget> itemsList = [];
for (var element in getOffersList) {
for (var element in _foundOffersList) {
itemsList.add(getItemCard(element));
}
@ -213,6 +207,18 @@ class _OffersAndDiscountsHomeState extends State<OffersAndDiscountsHome> {
);
}
void _runFilter(String enteredKeyword) {
List<OffersListModel> results = [];
if (enteredKeyword.isEmpty) {
results = getOffersList;
} else {
results = getOffersList.where((offer) => offer.title!.toLowerCase().contains(enteredKeyword.toLowerCase())).toList();
}
setState(() {
_foundOffersList = results;
});
}
void navigateToDetails(OffersListModel offersListModelObj) {
List<OffersListModel> getOffersDetailList = [];
getOffersDetailList.clear();
@ -258,6 +264,7 @@ class _OffersAndDiscountsHomeState extends State<OffersAndDiscountsHome> {
try {
Utils.showLoading(context);
getOffersList = await OffersAndDiscountsApiClient().getOffersList(currentCategoryID, 100);
_foundOffersList = getOffersList;
Utils.hideLoading(context);
setState(() {});
} catch (ex) {

@ -75,6 +75,7 @@ dependencies:
url_launcher: ^6.0.15
share: 2.0.4
flutter_rating_bar: ^4.0.1
pull_to_refresh: ^2.0.0
dev_dependencies:
flutter_test:

Loading…
Cancel
Save