327 lines
10 KiB
Dart
327 lines
10 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:ftc_mobile_app/ftc_mobile_app.dart';
|
|
import 'package:ftc_mobile_app/models/appointmentsListResponse/AppointmentsListResponse.dart';
|
|
import 'package:ftc_mobile_app/models/clients/recent_incidents_model.dart';
|
|
import 'package:ftc_mobile_app/utilities/extensions/custom_extensions.dart';
|
|
import 'package:get/get.dart';
|
|
|
|
import 'widgets/appointment_details.dart';
|
|
import 'widgets/recent_incident_detail_dialog.dart';
|
|
|
|
class AppDialog {
|
|
static String areYouSureText = "Are you sure?";
|
|
static bool alreadyShownUnauthorizedAlert = false;
|
|
|
|
static Widget titleText(String title) {
|
|
return CustomTextWidget(
|
|
text: title,
|
|
textAlign: TextAlign.center,
|
|
fontSize: 20,
|
|
fontWeight: FontWeight.w700,
|
|
);
|
|
}
|
|
|
|
static Widget messageText(String message) {
|
|
return CustomTextWidget(
|
|
text: message,
|
|
textAlign: TextAlign.center,
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.w400,
|
|
);
|
|
}
|
|
|
|
static Widget buttonsBar({
|
|
String button1Text = "No",
|
|
String button2Text = "Yes",
|
|
VoidCallback? onButton1Tap,
|
|
required VoidCallback onButton2Tap,
|
|
}) {
|
|
return SizedBox(
|
|
width: double.maxFinite,
|
|
height: 40.h,
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: CustomAppButton(
|
|
onTap: () {
|
|
if (onButton1Tap == null) {
|
|
Get.back();
|
|
} else {
|
|
onButton1Tap();
|
|
}
|
|
},
|
|
buttonText: button1Text,
|
|
textColor: Colors.black,
|
|
borderColor: Colors.grey,
|
|
buttonColor: Colors.white,
|
|
),
|
|
),
|
|
16.horizontalSpace,
|
|
Expanded(
|
|
child: CustomAppButton(
|
|
onTap: onButton2Tap,
|
|
buttonText: button2Text,
|
|
buttonColor: Get.theme.primaryColor,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
static Future successDialog({
|
|
required String title,
|
|
required String message,
|
|
required String buttonText,
|
|
required VoidCallback onDoneButtonClick,
|
|
bool canDismiss = true,
|
|
}) {
|
|
return Get.generalDialog(
|
|
barrierLabel: "",
|
|
barrierDismissible: canDismiss,
|
|
pageBuilder: (_, a1, a2) {
|
|
return AlertDialog(
|
|
shape: 15.toRoundedRectRadius(),
|
|
backgroundColor: Colors.white,
|
|
elevation: 0,
|
|
contentPadding: REdgeInsets.symmetric(horizontal: 24, vertical: 32),
|
|
content: WillPopScope(
|
|
onWillPop: () async => canDismiss,
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
// SvgPicture.asset(
|
|
// Assets.svgIcCheck,
|
|
// width: 50.r,
|
|
// height: 50.r,
|
|
// ),
|
|
// 16.verticalSpace,
|
|
titleText(title),
|
|
12.verticalSpace,
|
|
messageText(message),
|
|
24.verticalSpace,
|
|
CustomAppButton(
|
|
onTap: onDoneButtonClick,
|
|
buttonText: buttonText,
|
|
buttonColor: Get.theme.primaryColor,
|
|
).addPaddingHorizontal(24),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
static Future showDialogWithSingleActionButton(
|
|
{required String title,
|
|
required String message,
|
|
required VoidCallback onDoneButtonClick}) {
|
|
return Get.generalDialog(
|
|
barrierLabel: "",
|
|
barrierDismissible: true,
|
|
pageBuilder: (_, a1, a2) {
|
|
return AlertDialog(
|
|
shape: 15.toRoundedRectRadius(),
|
|
contentPadding: REdgeInsets.symmetric(horizontal: 32, vertical: 32),
|
|
backgroundColor: Colors.white,
|
|
elevation: 0,
|
|
insetPadding: REdgeInsets.all(24),
|
|
content: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
12.verticalSpace,
|
|
titleText(title),
|
|
16.verticalSpace,
|
|
messageText(message),
|
|
32.verticalSpace,
|
|
CustomAppButton(
|
|
onTap: onDoneButtonClick,
|
|
buttonText: "Done",
|
|
buttonColor: Get.theme.primaryColor,
|
|
).addPaddingHorizontal(24),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
static Future showDialogDeleteAccount(
|
|
{required VoidCallback onDeleteButtonClick}) {
|
|
return Get.generalDialog(
|
|
barrierLabel: "",
|
|
barrierDismissible: true,
|
|
pageBuilder: (_, a1, a2) {
|
|
return Center(
|
|
child: Card(
|
|
shape: 15.toRoundedRectRadius(),
|
|
color: Colors.white,
|
|
margin: REdgeInsets.symmetric(horizontal: 24),
|
|
child: Padding(
|
|
padding: REdgeInsets.symmetric(horizontal: 24.0, vertical: 32),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
SizedBox(width: double.maxFinite, height: 12.h),
|
|
titleText("Delete Account?"),
|
|
SizedBox(width: double.maxFinite, height: 16.h),
|
|
messageText("Are you sure you want to delete your account?"),
|
|
SizedBox(width: double.maxFinite, height: 32.h),
|
|
buttonsBar(onButton2Tap: onDeleteButtonClick),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
static Future showUnauthorizedAlert() async {
|
|
if (alreadyShownUnauthorizedAlert) {
|
|
return;
|
|
}
|
|
|
|
alreadyShownUnauthorizedAlert = true;
|
|
await Get.dialog(
|
|
WillPopScope(
|
|
onWillPop: () async => false,
|
|
child: UnconstrainedBox(
|
|
child: SizedBox(
|
|
width: 1.0.sw,
|
|
child: AlertDialog(
|
|
shape: 15.toRoundedRectRadius(),
|
|
contentPadding:
|
|
REdgeInsets.symmetric(horizontal: 32, vertical: 32),
|
|
insetPadding:
|
|
REdgeInsets.symmetric(horizontal: 24, vertical: 24),
|
|
backgroundColor: Colors.white,
|
|
content: Column(
|
|
children: [
|
|
Icon(
|
|
Icons.warning_amber_rounded,
|
|
color: Colors.red,
|
|
size: 65.r,
|
|
),
|
|
24.verticalSpace,
|
|
titleText(
|
|
"Session Expired",
|
|
),
|
|
12.verticalSpace,
|
|
messageText(
|
|
"Your session has been expired. Please log-in again to continue using the app.",
|
|
),
|
|
48.verticalSpace,
|
|
CustomAppButton(
|
|
onTap: () {
|
|
Get.back();
|
|
alreadyShownUnauthorizedAlert = false;
|
|
// FrequentFunctions.logout();
|
|
},
|
|
buttonText: "Log In",
|
|
buttonColor: Get.theme.primaryColor,
|
|
)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
barrierDismissible: false)
|
|
.then((value) {
|
|
alreadyShownUnauthorizedAlert = false;
|
|
});
|
|
}
|
|
|
|
static Future alertAndLogout(VoidCallback onTapYes) {
|
|
return _showLogoutAlert(onTapYes);
|
|
}
|
|
|
|
static Future _showLogoutAlert(Function() onTapYes) async {
|
|
// do not handle dialog dismiss, as it's already done
|
|
return openAlertDialog(
|
|
title: "Logout!",
|
|
message: "$areYouSureText Do you really want to logout from the app?",
|
|
onYesTap: onTapYes);
|
|
}
|
|
|
|
static Future<bool> showAlertAppExit() async {
|
|
var isOk = false;
|
|
|
|
await Get.generalDialog(
|
|
barrierLabel: "",
|
|
barrierDismissible: true,
|
|
pageBuilder: (_, a1, a2) {
|
|
return Center(
|
|
child: Card(
|
|
shape: 15.toRoundedRectRadius(),
|
|
color: Colors.white,
|
|
margin: REdgeInsets.symmetric(horizontal: 24),
|
|
child: Padding(
|
|
padding: REdgeInsets.symmetric(horizontal: 24.0, vertical: 32),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
SizedBox(width: double.maxFinite, height: 12.h),
|
|
titleText(areYouSureText),
|
|
SizedBox(width: double.maxFinite, height: 16.h),
|
|
titleText("Do you really want to exit from the app?"),
|
|
SizedBox(width: double.maxFinite, height: 32.h),
|
|
buttonsBar(onButton2Tap: () async {
|
|
isOk = true;
|
|
Get.back();
|
|
}),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
|
|
return isOk;
|
|
}
|
|
|
|
static Future openAlertDialog(
|
|
{required String title,
|
|
required String message,
|
|
required VoidCallback onYesTap}) {
|
|
return Get.generalDialog(
|
|
barrierLabel: "",
|
|
barrierDismissible: true,
|
|
pageBuilder: (_, a1, a2) {
|
|
return Center(
|
|
child: Card(
|
|
shape: 15.toRoundedRectRadius(),
|
|
color: Colors.white,
|
|
margin: REdgeInsets.symmetric(horizontal: 24),
|
|
child: Padding(
|
|
padding: REdgeInsets.symmetric(horizontal: 24.0, vertical: 32),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
SizedBox(width: double.maxFinite, height: 12.h),
|
|
titleText(title),
|
|
16.verticalSpace,
|
|
messageText(message),
|
|
SizedBox(width: double.maxFinite, height: 32.h),
|
|
buttonsBar(onButton2Tap: onYesTap),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
});
|
|
}
|
|
|
|
static showAppointmentDetailDialog(
|
|
{required AppointmentsListResponseData data}) {
|
|
Get.dialog(AppointmentDetailsDialog(data: data));
|
|
}
|
|
|
|
static showRecentIncidentDetailDialog({required RecentIncidentsModel data}) {
|
|
Get.dialog(RecentIncidentDetailDialog(data: data));
|
|
}
|
|
}
|