This repository has been archived on 2024-10-18. You can view files and clone it, but cannot push or open issues or pull requests.
ftc_patient_app/lib/utilities/frequent_functions.dart

222 lines
8.1 KiB
Dart

import 'package:get_time_ago/get_time_ago.dart';
import 'extensions/custom_extensions.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:ftc_mobile_app/ftc_mobile_app.dart';
import 'package:intl/intl.dart';
import 'package:pull_to_refresh_flutter3/pull_to_refresh_flutter3.dart';
class FrequentFunctions {
FrequentFunctions._();
static final _instance = FrequentFunctions._();
// static Rx<UserModel> userModel = UserModel.empty().obs;
// static ProfileDataModel profileDataModelNew = ProfileDataModel.fromJson(
// json.decode(LocalStorageManager.getSessionToken(
// tokenKey: LocalStorageKeys.kProfileModelKey)));
factory FrequentFunctions() {
return _instance;
}
static const noWidget = SizedBox.shrink();
static const waterDropHeader = WaterDropHeader(
waterDropColor: CustomAppColors.kSecondaryColor,
complete: FrequentFunctions.noWidget,
failed: FrequentFunctions.noWidget,
completeDuration: Duration.zero,
);
static DateFormat careNoteDateFormatter = DateFormat("dd/MM/yyyy, hh:mm aa");
void logoutButtonPressed(BuildContext context) {
// LocalStorageManager.removeSession(token: LocalStorageKeys.kUserModelKey);
// LocalStorageManager.removeSession(token: LocalStorageKeys.kProfileModelKey);
LocalStorageManager.clear();
Navigator.pushNamedAndRemoveUntil(
context, CustomRouteNames.kLoginScreenRoute, (route) => false);
}
static void showToast(
{required String message, Toast toast = Toast.LENGTH_SHORT}) {
Fluttertoast.showToast(
msg: message,
toastLength: toast,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 1,
backgroundColor: CustomAppColors.kBlackColor,
textColor: CustomAppColors.kPrimaryColor,
fontSize: 13.0,
);
}
// static void showDialog(
// {required BuildContext context,
// required String title,
// required String description,
// required DialogType type,
// Color btnOkColor = CustomAppColors.kSecondaryColor,
// Function? onOkBtnPressed}) {
// AwesomeDialog(
// customHeader: Image.asset(AssetsManager.kAppIcon),
// dismissOnBackKeyPress: true,
// context: context,
// dialogType: type,
// headerAnimationLoop: false,
// animType: AnimType.scale,
// btnOkColor: btnOkColor,
// title: title,
// dismissOnTouchOutside: true,
// desc: description,
// btnOkOnPress: () {
// if (onOkBtnPressed != null) {
// onOkBtnPressed();
// }
// },
// ).show();
// }
List<RotaShift> findDaysWithData(MonthWiseRecord monthWiseRecord) {
// print('Month: ${monthWiseRecord.id}');
List<RotaShift> rotaShiftListReturning = [];
for (var weekRecord in [
monthWiseRecord.week1,
monthWiseRecord.week2,
monthWiseRecord.week3,
monthWiseRecord.week4,
]) {
for (var day in [
weekRecord.mondayRecord,
weekRecord.tuesdayRecord,
weekRecord.wednesdayRecord,
weekRecord.thursdayRecord,
weekRecord.fridayRecord,
weekRecord.saturdayRecord,
weekRecord.sundayRecord
]) {
if (day.rotaShift.havingShift &&
day.rotaShift.shiftTime.isAfter(DateTime.now())) {
rotaShiftListReturning.add(day.rotaShift);
}
}
}
return rotaShiftListReturning;
}
static Future<DateTime?> datePicker(BuildContext context) async {
return await showDatePicker(
context: context,
initialDate: DateTime.now(),
firstDate: DateTime.now(),
lastDate: DateTime.now().add(const Duration(days: 365)),
);
}
static Future<TimeOfDay?> selectTime(BuildContext context,
{required TimeOfDay selectedTime, required Color themeColor}) =>
showTimePicker(
context: context,
initialTime: selectedTime,
initialEntryMode: TimePickerEntryMode.dialOnly,
confirmText: "CONFIRM",
helpText: "Select Time",
builder: (context, child) {
return MediaQuery(
data:
MediaQuery.of(context).copyWith(alwaysUse24HourFormat: false),
child: Theme(
data: Theme.of(context).copyWith(
timePickerTheme: TimePickerThemeData(
backgroundColor: Colors.white,
// hourMinuteShape: const RoundedRectangleBorder(
// borderRadius: BorderRadius.all(Radius.circular(8)),
// side: BorderSide(color: Colors.orange, width: 4),
// ),
dayPeriodBorderSide:
const BorderSide(color: Colors.black, width: 1),
dayPeriodColor: MaterialStateColor.resolveWith((states) =>
states.contains(MaterialState.selected)
? themeColor
: CustomAppColors.kSmokeColor),
// shape: const RoundedRectangleBorder(
// borderRadius: BorderRadius.all(Radius.circular(8)),
// side: BorderSide(color: Colors.orange, width: 4),
// ),
dayPeriodTextColor: Colors.black,
// dayPeriodTextStyle:
// textStyle12w500.copyWith(fontWeight: FontWeight.bold),
// dayPeriodShape: const RoundedRectangleBorder(
// borderRadius: BorderRadius.all(Radius.circular(8)),
// side: BorderSide(color: Colors.orange, width: 4),
// ),
hourMinuteColor: MaterialStateColor.resolveWith((states) =>
states.contains(MaterialState.selected)
? themeColor
: CustomAppColors.kSmokeColor),
hourMinuteTextColor: MaterialStateColor.resolveWith(
(states) => states.contains(MaterialState.selected)
? Colors.black
: Colors.black),
// hourMinuteTextStyle: const TextStyle(
// fontSize: 32, fontWeight: FontWeight.bold),
dialHandColor: themeColor,
dialBackgroundColor: CustomAppColors.kSmokeColor,
dialTextColor: MaterialStateColor.resolveWith((states) =>
states.contains(MaterialState.selected)
? Colors.black
: Colors.black),
// helpTextStyle: textStyle14w600,
inputDecorationTheme: const InputDecorationTheme(
border: InputBorder.none,
contentPadding: EdgeInsets.all(0),
),
entryModeIconColor: themeColor,
),
textButtonTheme: TextButtonThemeData(
style: ButtonStyle(
// backgroundColor: MaterialStateColor.resolveWith((states) => Colors.orange),
foregroundColor: MaterialStateColor.resolveWith(
(states) => Colors.black),
// overlayColor: MaterialStateColor.resolveWith((states) => Colors.deepOrange),
),
),
),
child: child!,
),
);
});
//eg: a = ["A", "B", "C"], b = ["1", "2"]
// zip(a, b) => ["A", "1", "B", "2", "C"]
static Iterable<T> zip<T>(Iterable<T> a, Iterable<T> b) sync* {
final ita = a.iterator;
final itb = b.iterator;
bool hasa, hasb;
while ((hasa = ita.moveNext()) | (hasb = itb.moveNext())) {
if (hasa) yield ita.current;
if (hasb) yield itb.current;
}
}
static Widget centerText({required String text}) {
return Center(
child: CustomTextWidget(
text: text,
fontSize: 14.sp,
fontWeight: FontWeight.w600,
));
}
static String toTimesAgo(String? dateTime) {
return (dateTime.isNullOrEmpty())
? ""
: GetTimeAgo.parse(DateTime.parse(dateTime!).toLocal());
}
}