You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
512 lines
21 KiB
Dart
512 lines
21 KiB
Dart
// older code....
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:test_sa/controllers/api_routes/api_manager.dart';
|
|
import 'package:test_sa/dashboard_latest/dashboard_provider.dart';
|
|
import 'package:test_sa/extensions/context_extension.dart';
|
|
import 'package:test_sa/extensions/int_extensions.dart';
|
|
import 'package:test_sa/extensions/text_extensions.dart';
|
|
import 'package:test_sa/extensions/widget_extensions.dart';
|
|
import 'package:test_sa/models/enums/user_types.dart';
|
|
import 'package:test_sa/new_views/app_style/app_color.dart';
|
|
import 'package:test_sa/new_views/common_widgets/custom_badge.dart';
|
|
import 'package:test_sa/new_views/pages/land_page/requests_list_page.dart';
|
|
import 'package:test_sa/controllers/providers/api/all_requests_provider.dart';
|
|
|
|
class RequestsFragment extends StatelessWidget {
|
|
const RequestsFragment({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Consumer<DashBoardProvider>(
|
|
builder: (context, snapshot, _) => GridView(
|
|
padding: const EdgeInsets.only(left: 16, right: 16),
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
shrinkWrap: true,
|
|
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 4, childAspectRatio: 72 / 84, crossAxisSpacing: 2, mainAxisSpacing: 12),
|
|
children: [
|
|
listItem(
|
|
snapshot.dashboardCount?.data?.countHighPriority ?? 0,
|
|
"high_priority",
|
|
context.translation.highPriority,
|
|
context,
|
|
snapshot.isAllCountLoading,
|
|
0,
|
|
context.isDark ? AppColor.redStatus(context) : AppColor.red30,
|
|
),
|
|
listItem(snapshot.dashboardCount?.data?.countOverdue ?? 0, "overdue", context.translation.overdue, context, snapshot.isAllCountLoading, 1, AppColor.yellowIcon(context)),
|
|
listItem(ApiManager.instance.user?.type == UsersTypes.engineer ? snapshot.dashboardCount?.data?.countInprogress ?? 0 : snapshot.dashboardCount?.data?.countOpen ?? 0, "new_request",
|
|
ApiManager.instance.user?.type == UsersTypes.engineer ? context.translation.inProgress : context.translation.newR, context, snapshot.isAllCountLoading, 2, AppColor.primary10),
|
|
listItem(snapshot.dashboardCount?.data?.countComplete ?? 0, "complete_request", context.translation.completed, context, snapshot.isAllCountLoading, 3, AppColor.greenStatus(context)),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget listItem(int value, String icon, String title, BuildContext context, bool isLoading, int index, Color iconColor) {
|
|
return GestureDetector(
|
|
onTap: isLoading
|
|
? null
|
|
: () {
|
|
Navigator.push(context, MaterialPageRoute(builder: (context) => RequestsListPage(index, title)));
|
|
},
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
8.height,
|
|
CustomBadge(
|
|
value: isLoading ? 0 : value,
|
|
child: Container(
|
|
child: (icon ?? "").toSvgAsset(height: 26, width: 26, color: iconColor).toShimmer(isShow: isLoading),
|
|
).toShadowCircleContainer(context, padding: 17),
|
|
),
|
|
10.height,
|
|
Text(
|
|
title,
|
|
textAlign: TextAlign.center,
|
|
style: AppTextStyles.tinyFont.copyWith(
|
|
color: context.isDark ? AppColor.neutral30 : AppColor.black20,
|
|
),
|
|
).toShimmer(isShow: isLoading),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
// import 'package:flutter/material.dart';
|
|
// import 'package:provider/provider.dart';
|
|
// import 'package:test_sa/controllers/api_routes/api_manager.dart';
|
|
// import 'package:test_sa/controllers/providers/api/all_requests_provider.dart';
|
|
// import 'package:test_sa/controllers/providers/api/notifications_provider.dart';
|
|
// import 'package:test_sa/controllers/providers/api/user_provider.dart';
|
|
// import 'package:test_sa/extensions/context_extension.dart';
|
|
// import 'package:test_sa/extensions/int_extensions.dart';
|
|
// import 'package:test_sa/extensions/text_extensions.dart';
|
|
// import 'package:test_sa/extensions/widget_extensions.dart';
|
|
// import 'package:badges/badges.dart' as badges;
|
|
// import 'package:test_sa/models/enums/user_types.dart';
|
|
// import 'package:test_sa/new_views/app_style/app_color.dart';
|
|
// import 'package:test_sa/new_views/common_widgets/app_floating_action_button.dart';
|
|
// import 'package:test_sa/new_views/pages/land_page/requests_list_page.dart';
|
|
//
|
|
// class RequestsFragment extends StatelessWidget {
|
|
// const RequestsFragment({Key? key}) : super(key: key);
|
|
//
|
|
// @override
|
|
// Widget build(BuildContext context) {
|
|
// return Consumer<AllRequestsProvider>(
|
|
// builder: (context, snapshot, _) => RefreshIndicator(
|
|
// onRefresh: () async {
|
|
// snapshot.getRequests();
|
|
// await Provider.of<NotificationsProvider>(context, listen: false).getSystemNotifications(
|
|
// user: Provider.of<UserProvider>(context, listen: false).user,
|
|
// resetProvider: true,
|
|
// );
|
|
// return Future.delayed(const Duration(milliseconds: 250));
|
|
// },
|
|
// child: Row(
|
|
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
// children: _buildListItems(context, snapshot),
|
|
// ),
|
|
// ),
|
|
// );
|
|
// }
|
|
//
|
|
// List<Widget> _buildListItems(BuildContext context, AllRequestsProvider snapshot) {
|
|
// final Map<String, dynamic> requestItems = {
|
|
// 'high_priority': {
|
|
// 'count': snapshot.highPriorityRequests?.total?.count,
|
|
// 'translation': context.translation.highPriority,
|
|
// 'isLoading': snapshot.isAllLoading,
|
|
// 'color': context.isDark ? AppColor.redStatus(context) : AppColor.red50,
|
|
// },
|
|
// 'overdue': {
|
|
// 'count': snapshot.overdueRequests?.total?.count,
|
|
// 'translation': context.translation.overdue,
|
|
// 'isLoading': snapshot.isAllLoading,
|
|
// 'color': AppColor.yellowStatus(context),
|
|
// },
|
|
// 'new_request': {
|
|
// 'count': snapshot.openRequests?.total?.count,
|
|
// 'translation': ApiManager.instance.user.type == UsersTypes.engineer ? context.translation.inProgress : context.translation.newR,
|
|
// 'isLoading': snapshot.isAllLoading,
|
|
// 'color': AppColor.primary40,
|
|
// },
|
|
// 'complete_request': {
|
|
// 'count': snapshot.completedRequests?.total?.count,
|
|
// 'translation': context.translation.completed,
|
|
// 'isLoading': snapshot.isAllLoading,
|
|
// 'color': AppColor.greenStatus(context),
|
|
// },
|
|
// };
|
|
//
|
|
// return requestItems.entries.map((entry) {
|
|
// final key = entry.key;
|
|
// final value = entry.value;
|
|
//
|
|
// return listItem(
|
|
// value['count'],
|
|
// key,
|
|
// value['translation'],
|
|
// context,
|
|
// value['isLoading'],
|
|
// requestItems.keys.toList().indexOf(key),
|
|
// value['color'],
|
|
// );
|
|
// }).toList();
|
|
// }
|
|
//
|
|
// Widget listItem(
|
|
// int value,
|
|
// String icon,
|
|
// String title,
|
|
// BuildContext context,
|
|
// bool isLoading,
|
|
// int index,
|
|
// Color iconColor,
|
|
// ) {
|
|
// return GestureDetector(
|
|
// onTap: isLoading
|
|
// ? null
|
|
// : () {
|
|
// Navigator.push(
|
|
// context,
|
|
// MaterialPageRoute(
|
|
// builder: (context) => RequestsListPage(index),
|
|
// ),
|
|
// );
|
|
// // Provider.of<AllRequestsProvider>(context, listen: false).isAllLoading = true;
|
|
// // Provider.of<AllRequestsProvider>(context, listen: false)
|
|
// // .getRequests();
|
|
// },
|
|
// child: Column(
|
|
// crossAxisAlignment: CrossAxisAlignment.start,
|
|
// children: [
|
|
// value != null && value > 0 && !isLoading
|
|
// ? badges.Badge(
|
|
// badgeContent: Text(
|
|
// value.toString(),
|
|
// style: const TextStyle(
|
|
// color: AppColor.white20,
|
|
// fontWeight: FontWeight.normal,
|
|
// ),
|
|
// ),
|
|
// badgeStyle: const badges.BadgeStyle(padding: EdgeInsets.all(4), badgeColor: AppColor.red30),
|
|
// child: Container(
|
|
// child: (icon ?? "").toSvgAsset(height: 26, width: 26, color: iconColor)?.toShimmer(isShow: isLoading),
|
|
// ).toShadowCircleContainer(context, padding: 18),
|
|
// )
|
|
// : Container(
|
|
// child: (icon ?? "").toSvgAsset(height: 26, width: 26, color: iconColor)?.toShimmer(isShow: isLoading),
|
|
// ).toShadowCircleContainer(context, padding: 18),
|
|
// 10.height,
|
|
// Text(
|
|
// title,
|
|
// style: AppTextStyles.bodyText.copyWith(
|
|
// color: context.isDark ? AppColor.neutral30 : AppColor.neutral50,
|
|
// ),
|
|
// ),
|
|
// ],
|
|
// ),
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// import 'package:flutter/material.dart';
|
|
// import 'package:provider/provider.dart';
|
|
// import 'package:test_sa/controllers/api_routes/api_manager.dart';
|
|
// import 'package:test_sa/controllers/providers/api/all_requests_provider.dart';
|
|
// import 'package:test_sa/controllers/providers/api/notifications_provider.dart';
|
|
// import 'package:test_sa/controllers/providers/api/user_provider.dart';
|
|
// import 'package:test_sa/extensions/context_extension.dart';
|
|
// import 'package:test_sa/extensions/int_extensions.dart';
|
|
// import 'package:test_sa/extensions/text_extensions.dart';
|
|
// import 'package:test_sa/extensions/widget_extensions.dart';
|
|
// import 'package:badges/badges.dart' as badges;
|
|
// import 'package:test_sa/models/enums/user_types.dart';
|
|
// import 'package:test_sa/new_views/app_style/app_color.dart';
|
|
// import 'package:test_sa/new_views/common_widgets/app_floating_action_button.dart';
|
|
// import 'package:test_sa/new_views/pages/land_page/requests_list_page.dart';
|
|
//
|
|
// class RequestsFragment extends StatelessWidget {
|
|
// const RequestsFragment({Key? key}) : super(key: key);
|
|
//
|
|
// @override
|
|
// Widget build(BuildContext context) {
|
|
// return Scaffold(
|
|
// // todo check here, nurse can add request not engineer
|
|
// floatingActionButton: const AppFloatingActionButton(),
|
|
// body: Consumer<AllRequestsProvider>(
|
|
// builder: (context, snapshot, _) => RefreshIndicator(
|
|
// onRefresh: () {
|
|
// snapshot.getRequests();
|
|
// Provider.of<NotificationsProvider>(context, listen: false)
|
|
// .getSystemNotifications(
|
|
// user: Provider.of<UserProvider>(context, listen: false)
|
|
// .user,
|
|
// resetProvider: true);
|
|
// return Future.delayed(const Duration(microseconds: 250));
|
|
// },
|
|
// child: Container(
|
|
// height: 200.toScreenHeight,
|
|
// color: Colors.blue,
|
|
// child: Wrap(
|
|
// children: [
|
|
// listItem(
|
|
// snapshot.highPriorityRequests?.total?.count,
|
|
// "high_priority",
|
|
// context.translation.highPriority,
|
|
// context,
|
|
// snapshot.isHighPriorityLoading,
|
|
// 0,
|
|
// context.isDark ? AppColor.redStatus(context) : AppColor.red50,
|
|
// ),
|
|
// ],
|
|
// ),
|
|
// // child: ListView(
|
|
// // // padding: const EdgeInsets.only(left: 16, right: 16, bottom: 16),
|
|
// // children: [
|
|
// // listItem(
|
|
// // snapshot.highPriorityRequests?.total?.count,
|
|
// // "high_priority",
|
|
// // context.translation.highPriority,
|
|
// // context,
|
|
// // snapshot.isHighPriorityLoading,
|
|
// // 0,
|
|
// // context.isDark ? AppColor.redStatus(context) : AppColor.red50,
|
|
// // ),
|
|
// // listItem(
|
|
// // snapshot.overdueRequests?.total?.count,
|
|
// // "overdue",
|
|
// // context.translation.overdue,
|
|
// // context,
|
|
// // snapshot.isOverdueLoading,
|
|
// // 1,
|
|
// // AppColor.yellowStatus(context),
|
|
// // ),
|
|
// // listItem(
|
|
// // snapshot.openRequests?.total?.count,
|
|
// // "new_request",
|
|
// // ApiManager.instance.user.type == UsersTypes.engineer
|
|
// // ? context.translation.inProgress
|
|
// // : context.translation.newR,
|
|
// // context,
|
|
// // snapshot.isOpenLoading,
|
|
// // 2,
|
|
// // AppColor.primary40,
|
|
// // ),
|
|
// // listItem(
|
|
// // snapshot.completedRequests?.total?.count,
|
|
// // "complete_request",
|
|
// // context.translation.completed,
|
|
// // context,
|
|
// // snapshot.isCompleteLoading,
|
|
// // 3,
|
|
// // AppColor.greenStatus(context),
|
|
// // ),
|
|
// // ],
|
|
// // ),
|
|
// )),
|
|
// ),
|
|
// );
|
|
// }
|
|
//
|
|
// Widget listItem(
|
|
// int value,
|
|
// String icon,
|
|
// String title,
|
|
// BuildContext context,
|
|
// bool isLoading,
|
|
// int index,
|
|
// Color iconColor,
|
|
// ) {
|
|
// value = 4;
|
|
// return GestureDetector(
|
|
// onTap: isLoading
|
|
// ? null
|
|
// : () async {
|
|
// await Navigator.push(
|
|
// context,
|
|
// MaterialPageRoute(
|
|
// builder: (context) => RequestsListPage(index)));
|
|
// Provider.of<AllRequestsProvider>(context, listen: false)
|
|
// .getRequests();
|
|
// },
|
|
// child: Column(
|
|
// crossAxisAlignment: CrossAxisAlignment.start,
|
|
// children: [
|
|
// value!=null&&value > 0
|
|
// ? badges.Badge(
|
|
// badgeContent: Text(
|
|
// value.toString(),
|
|
// style: const TextStyle(
|
|
// color: AppColor.white20,
|
|
// // fontSize: 1.3.h,
|
|
// fontWeight: FontWeight.normal),
|
|
// ),
|
|
// badgeStyle: badges.BadgeStyle(
|
|
// padding: EdgeInsets.all(9),
|
|
// ),
|
|
// child: Container(
|
|
// padding: const EdgeInsets.all(20),
|
|
// decoration: const BoxDecoration(
|
|
// shape: BoxShape.circle,
|
|
// //TODO add color according to theme...
|
|
// color: AppColor.white20, // Background color of the circle
|
|
// ),
|
|
// child: (icon ?? "")
|
|
// .toSvgAsset(height: 40, width: 40, color: iconColor)
|
|
// ?.toShimmer(isShow: isLoading),
|
|
// ))
|
|
// : Container(
|
|
// padding: const EdgeInsets.all(20),
|
|
// decoration: const BoxDecoration(
|
|
// shape: BoxShape.circle,
|
|
// //TODO add color according to theme...
|
|
// color: AppColor.white20, // Background color of the circle
|
|
// ),
|
|
// child: (icon ?? "")
|
|
// .toSvgAsset(height: 48, width: 48, color: iconColor)
|
|
// ?.toShimmer(isShow: isLoading),
|
|
// ),
|
|
// // Container(
|
|
// // padding: const EdgeInsets.all(20),
|
|
// // decoration: const BoxDecoration(
|
|
// // shape: BoxShape.circle,
|
|
// // //TODO add color according to theme...
|
|
// // color: AppColor.white20, // Background color of the circle
|
|
// // ),
|
|
// // child: (icon ?? "")
|
|
// // .toSvgAsset(height: 48, width: 48, color: iconColor)
|
|
// // ?.toShimmer(isShow: isLoading),
|
|
// // ),
|
|
// 20.height,
|
|
// Text(
|
|
// title,
|
|
// style: AppTextStyles.heading5.copyWith(
|
|
// color: context.isDark ? AppColor.neutral30 : AppColor.neutral50,
|
|
// ),
|
|
// ),
|
|
// // Text(
|
|
// // "$title\n${context.translation.requests}",
|
|
// // style: AppTextStyles.heading5.copyWith(
|
|
// // color: context.isDark ? AppColor.neutral30 : AppColor.neutral50,
|
|
// // ),
|
|
// // ).toShimmer(isShow: isLoading),
|
|
// // 8.height,
|
|
// // Row(
|
|
// // mainAxisSize: MainAxisSize.min,
|
|
// // children: [
|
|
// // Text(
|
|
// // context.translation.viewDetails,
|
|
// // style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.primary40 : AppColor.primary50),
|
|
// // ),
|
|
// // 4.width,
|
|
// // Icon(
|
|
// // Icons.arrow_forward,
|
|
// // color: context.isDark ? AppColor.primary40 : AppColor.primary50,
|
|
// // size: 14,
|
|
// // )
|
|
// // ],
|
|
// // ).toShimmer(isShow: isLoading),
|
|
// ],
|
|
// ),
|
|
// );
|
|
// }
|
|
//
|
|
// // Widget listItem(int value, String icon, String title, BuildContext context, bool isLoading, int index, Color iconColor) {
|
|
// // return Column(
|
|
// // crossAxisAlignment: CrossAxisAlignment.start,
|
|
// // children: [
|
|
// // Row(
|
|
// // crossAxisAlignment: CrossAxisAlignment.start,
|
|
// // children: [
|
|
// // //TODO add this to badges
|
|
// // // Text(
|
|
// // // value?.toString() ?? "-",
|
|
// // // style: AppTextStyles.heading1.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral50, height: 1),
|
|
// // // ).toShimmer(isShow: isLoading).expanded,
|
|
// // // 8.width,
|
|
// // (icon ?? "").toSvgAsset(height: 48, width: 48, color: iconColor)?.toShimmer(isShow: isLoading),
|
|
// // ],
|
|
// // ),
|
|
// // // Text(
|
|
// // // "$title\n${context.translation.requests}",
|
|
// // // style: AppTextStyles.heading5.copyWith(
|
|
// // // color: context.isDark ? AppColor.neutral30 : AppColor.neutral50,
|
|
// // // ),
|
|
// // // ).toShimmer(isShow: isLoading),
|
|
// // // 8.height,
|
|
// // // Row(
|
|
// // // mainAxisSize: MainAxisSize.min,
|
|
// // // children: [
|
|
// // // Text(
|
|
// // // context.translation.viewDetails,
|
|
// // // style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.primary40 : AppColor.primary50),
|
|
// // // ),
|
|
// // // 4.width,
|
|
// // // Icon(
|
|
// // // Icons.arrow_forward,
|
|
// // // color: context.isDark ? AppColor.primary40 : AppColor.primary50,
|
|
// // // size: 14,
|
|
// // // )
|
|
// // // ],
|
|
// // // ).toShimmer(isShow: isLoading),
|
|
// // ],
|
|
// // ).toShadowContainer(context).onPress(isLoading
|
|
// // ? null
|
|
// // : () async {
|
|
// // await Navigator.push(context, MaterialPageRoute(builder: (context) => RequestsListPage(index)));
|
|
// // Provider.of<AllRequestsProvider>(context, listen: false).getRequests();
|
|
// // });
|
|
// // }
|
|
// }
|
|
// Widget listItem(int value, String icon, String title, BuildContext context, bool isLoading, int index, Color iconColor) {
|
|
// return Column(
|
|
// crossAxisAlignment: CrossAxisAlignment.start,
|
|
// children: [
|
|
// Row(
|
|
// crossAxisAlignment: CrossAxisAlignment.start,
|
|
// children: [
|
|
// Text(
|
|
// value?.toString() ?? "-",
|
|
// style: AppTextStyles.bodyText2.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral50, height: 1),
|
|
// ).toShimmer(isShow: isLoading).expanded,
|
|
// 8.width,
|
|
// (icon ?? "").toSvgAsset(height: 48, width: 48, color: iconColor)?.toShimmer(isShow: isLoading),
|
|
// ],
|
|
// ).expanded,
|
|
// Text(
|
|
// "$title\n${context.translation.requests}",
|
|
// style: AppTextStyles.bodyText2.copyWith(
|
|
// color: context.isDark ? AppColor.neutral30 : AppColor.neutral50,
|
|
// ),
|
|
// ).toShimmer(isShow: isLoading),
|
|
// // 8.height,
|
|
// // Row(
|
|
// // mainAxisSize: MainAxisSize.min,
|
|
// // children: [
|
|
// // Text(
|
|
// // context.translation.viewDetails,
|
|
// // style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.primary40 : AppColor.primary50),
|
|
// // ),
|
|
// // 4.width,
|
|
// // Icon(
|
|
// // Icons.arrow_forward,
|
|
// // color: context.isDark ? AppColor.primary40 : AppColor.primary50,
|
|
// // size: 14,
|
|
// // )
|
|
// // ],
|
|
// // ).toShimmer(isShow: isLoading),
|
|
// ],
|
|
// ).toShadowContainer(context, padding: 0).onPress(isLoading
|
|
// ? null
|
|
// : () async {
|
|
// await Navigator.push(context, MaterialPageRoute(builder: (context) => RequestsListPage(index)));
|
|
// Provider.of<AllRequestsProvider>(context, listen: false).getRequests();
|
|
// });
|
|
// }
|