|
|
|
|
@ -1,11 +1,17 @@
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:intl/intl.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
import 'package:table_calendar/table_calendar.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/new_views/app_style/app_color.dart';
|
|
|
|
|
|
|
|
|
|
import '../../../../controllers/providers/api/all_requests_provider.dart';
|
|
|
|
|
import '../requests/asset_item_view.dart';
|
|
|
|
|
import '../requests/gas_refill_item_view.dart';
|
|
|
|
|
import '../requests/ppm_item_view.dart';
|
|
|
|
|
import '../requests/service_request_item_view.dart';
|
|
|
|
|
import 'calender_days_card.dart';
|
|
|
|
|
|
|
|
|
|
class WeeklyFragment extends StatefulWidget {
|
|
|
|
|
@ -18,12 +24,15 @@ class WeeklyFragment extends StatefulWidget {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _WeeklyFragmentState extends State<WeeklyFragment> {
|
|
|
|
|
DateTime currentDateTime = DateTime.now();
|
|
|
|
|
PageController _controller;
|
|
|
|
|
DateTime _initialDate, _firstDate, _lastDate;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
_initialDate = DateTime.now();
|
|
|
|
|
_firstDate = DateTime.utc(2010, 10, 16);
|
|
|
|
|
_lastDate = DateTime.utc(2030, 3, 14);
|
|
|
|
|
Provider.of<AllRequestsProvider>(context, listen: false).getCalenderRequests(from: DateTime.now().subtract(const Duration(days: 7)), to: DateTime.now());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
@ -34,68 +43,106 @@ class _WeeklyFragmentState extends State<WeeklyFragment> {
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return SingleChildScrollView(
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
TableCalendar(
|
|
|
|
|
firstDay: DateTime.utc(2010, 10, 16),
|
|
|
|
|
lastDay: DateTime.utc(2030, 3, 14),
|
|
|
|
|
focusedDay: DateTime.now(),
|
|
|
|
|
calendarFormat: CalendarFormat.week,
|
|
|
|
|
weekendDays: const [],
|
|
|
|
|
onCalendarCreated: (controller) {
|
|
|
|
|
_controller = controller;
|
|
|
|
|
},
|
|
|
|
|
calendarBuilders: CalendarBuilders(
|
|
|
|
|
headerTitleBuilder: (context, dateTime) => Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
|
children: [
|
|
|
|
|
DateFormat("EEEE, d MMMM, yyyy").format(dateTime).heading5(context),
|
|
|
|
|
8.height,
|
|
|
|
|
const Divider().defaultStyle(context),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
dowBuilder: (context, dateTime) {
|
|
|
|
|
final day = DateFormat("EE").format(dateTime).toUpperCase();
|
|
|
|
|
return Align(alignment: Alignment.center, child: day.bodyText(context).custom(color: AppColor.neutral50));
|
|
|
|
|
},
|
|
|
|
|
defaultBuilder: (context, dateTime, _) {
|
|
|
|
|
final day = DateFormat("d").format(dateTime);
|
|
|
|
|
return CalendarDaysCard(day: day);
|
|
|
|
|
child: Consumer<AllRequestsProvider>(builder: (context, snapshot, _) {
|
|
|
|
|
return Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
snapshot.isCalendarLoading
|
|
|
|
|
? const Center(child: CircularProgressIndicator())
|
|
|
|
|
: TableCalendar(
|
|
|
|
|
firstDay: _firstDate,
|
|
|
|
|
lastDay: _lastDate,
|
|
|
|
|
focusedDay: _initialDate,
|
|
|
|
|
calendarFormat: CalendarFormat.week,
|
|
|
|
|
weekendDays: const [],
|
|
|
|
|
onCalendarCreated: (controller) {},
|
|
|
|
|
calendarBuilders: CalendarBuilders(
|
|
|
|
|
headerTitleBuilder: (context, dateTime) => Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
|
children: [
|
|
|
|
|
DateFormat("EEEE, d MMMM, yyyy").format(dateTime).heading5(context),
|
|
|
|
|
8.height,
|
|
|
|
|
const Divider().defaultStyle(context),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
dowBuilder: (context, dateTime) {
|
|
|
|
|
final day = DateFormat("EE").format(dateTime).toUpperCase();
|
|
|
|
|
return Align(alignment: Alignment.center, child: day.bodyText(context).custom(color: AppColor.neutral50));
|
|
|
|
|
},
|
|
|
|
|
defaultBuilder: (context, dateTime, _) {
|
|
|
|
|
final day = DateFormat("d").format(dateTime);
|
|
|
|
|
return CalendarDaysCard(
|
|
|
|
|
day: day,
|
|
|
|
|
fill: snapshot.calendarRequests.requestsDetails?.firstWhere(
|
|
|
|
|
(element) => (element.date != null) && (DateTime.tryParse(element.date)?.difference(dateTime)?.inDays == 0),
|
|
|
|
|
orElse: () => null,
|
|
|
|
|
) !=
|
|
|
|
|
null,
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
daysOfWeekHeight: 35.toScreenHeight,
|
|
|
|
|
headerStyle: const HeaderStyle(leftChevronVisible: false, rightChevronVisible: false, formatButtonVisible: false),
|
|
|
|
|
calendarStyle: CalendarStyle(
|
|
|
|
|
isTodayHighlighted: false,
|
|
|
|
|
defaultTextStyle: AppTextStyles.bodyText,
|
|
|
|
|
defaultDecoration: const BoxDecoration(shape: BoxShape.circle, color: AppColor.neutral30),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
if (snapshot.calendarRequests?.requestsDetails?.isNotEmpty ?? false) const Divider().defaultStyle(context),
|
|
|
|
|
ListView.separated(
|
|
|
|
|
shrinkWrap: true,
|
|
|
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
|
|
|
itemBuilder: (cxt, index) {
|
|
|
|
|
final list = snapshot.calendarRequests.requestsDetails;
|
|
|
|
|
if (snapshot.isCalendarLoading) return const SizedBox().toRequestShimmer(cxt, snapshot.isCalendarLoading);
|
|
|
|
|
bool isServiceRequest = list[index].nameOfType == "ServiceRequest";
|
|
|
|
|
bool isGasRefill = list[index].nameOfType == "GasRefill";
|
|
|
|
|
bool isAssetTransfer = list[index].nameOfType == "AssetTransfer";
|
|
|
|
|
bool isPPMs = list[index].nameOfType == "PPMs";
|
|
|
|
|
|
|
|
|
|
return isServiceRequest
|
|
|
|
|
? ServiceRequestItemView(list[index])
|
|
|
|
|
: isGasRefill
|
|
|
|
|
? GasRefillItemView(list[index])
|
|
|
|
|
: isPPMs
|
|
|
|
|
? PpmItemView(list[index])
|
|
|
|
|
: isAssetTransfer
|
|
|
|
|
? AssetItemView(list[index])
|
|
|
|
|
: Container(
|
|
|
|
|
height: 100,
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
color: Colors.grey,
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
separatorBuilder: (cxt, index) => 8.height,
|
|
|
|
|
itemCount: snapshot.isCalendarLoading ? 6 : snapshot.calendarRequests.requestsDetails.length,
|
|
|
|
|
),
|
|
|
|
|
daysOfWeekHeight: 35.toScreenHeight,
|
|
|
|
|
headerStyle: const HeaderStyle(leftChevronVisible: false, rightChevronVisible: false, formatButtonVisible: false),
|
|
|
|
|
calendarStyle: CalendarStyle(
|
|
|
|
|
isTodayHighlighted: false,
|
|
|
|
|
defaultTextStyle: AppTextStyles.bodyText,
|
|
|
|
|
defaultDecoration: const BoxDecoration(shape: BoxShape.circle, color: AppColor.neutral30),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
// TableCalendar(
|
|
|
|
|
// headerVisible: false,
|
|
|
|
|
// calendarFormat: CalendarFormat.week,
|
|
|
|
|
// firstDay: DateTime.utc(2010, 10, 16),
|
|
|
|
|
// lastDay: DateTime.utc(2030, 3, 14),
|
|
|
|
|
// focusedDay: currentDateTime,
|
|
|
|
|
// currentDay: currentDateTime,
|
|
|
|
|
// rowHeight: 37,
|
|
|
|
|
// calendarStyle: CalendarStyle(
|
|
|
|
|
// todayDecoration: cellDecoration(),
|
|
|
|
|
// todayTextStyle: AppTextStyles.bodyText.copyWith(color: const Color(0xFF2B353E)),
|
|
|
|
|
// selectedTextStyle: AppTextStyles.bodyText.copyWith(color: const Color(0xFF2B353E)),
|
|
|
|
|
// rangeStartTextStyle: AppTextStyles.bodyText.copyWith(color: const Color(0xFF2B353E)),
|
|
|
|
|
// rangeEndTextStyle: AppTextStyles.bodyText.copyWith(color: const Color(0xFF2B353E)),
|
|
|
|
|
// ),
|
|
|
|
|
// daysOfWeekStyle: DaysOfWeekStyle(
|
|
|
|
|
// weekdayStyle: AppTextStyles.bodyText.copyWith(color: AppColor.neutral50),
|
|
|
|
|
// weekendStyle: AppTextStyles.bodyText.copyWith(color: AppColor.neutral50),
|
|
|
|
|
// ),
|
|
|
|
|
// availableGestures: AvailableGestures.none,
|
|
|
|
|
// ),
|
|
|
|
|
],
|
|
|
|
|
).toShadowContainer(context),
|
|
|
|
|
);
|
|
|
|
|
// TableCalendar(
|
|
|
|
|
// headerVisible: false,
|
|
|
|
|
// calendarFormat: CalendarFormat.week,
|
|
|
|
|
// firstDay: DateTime.utc(2010, 10, 16),
|
|
|
|
|
// lastDay: DateTime.utc(2030, 3, 14),
|
|
|
|
|
// focusedDay: currentDateTime,
|
|
|
|
|
// currentDay: currentDateTime,
|
|
|
|
|
// rowHeight: 37,
|
|
|
|
|
// calendarStyle: CalendarStyle(
|
|
|
|
|
// todayDecoration: cellDecoration(),
|
|
|
|
|
// todayTextStyle: AppTextStyles.bodyText.copyWith(color: const Color(0xFF2B353E)),
|
|
|
|
|
// selectedTextStyle: AppTextStyles.bodyText.copyWith(color: const Color(0xFF2B353E)),
|
|
|
|
|
// rangeStartTextStyle: AppTextStyles.bodyText.copyWith(color: const Color(0xFF2B353E)),
|
|
|
|
|
// rangeEndTextStyle: AppTextStyles.bodyText.copyWith(color: const Color(0xFF2B353E)),
|
|
|
|
|
// ),
|
|
|
|
|
// daysOfWeekStyle: DaysOfWeekStyle(
|
|
|
|
|
// weekdayStyle: AppTextStyles.bodyText.copyWith(color: AppColor.neutral50),
|
|
|
|
|
// weekendStyle: AppTextStyles.bodyText.copyWith(color: AppColor.neutral50),
|
|
|
|
|
// ),
|
|
|
|
|
// availableGestures: AvailableGestures.none,
|
|
|
|
|
// ),
|
|
|
|
|
],
|
|
|
|
|
).toShadowContainer(context);
|
|
|
|
|
}),
|
|
|
|
|
).paddingOnly(start: 16, end: 16);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BoxDecoration cellDecoration({Color color}) => BoxDecoration(color: color ?? Colors.transparent, shape: BoxShape.circle);
|
|
|
|
|
|