NEW: MIh Alerts

This commit is contained in:
2025-11-20 10:56:15 +02:00
parent b69a52a5a8
commit 00cd5488e3
66 changed files with 3188 additions and 5130 deletions

View File

@@ -1,4 +1,5 @@
import 'package:go_router/go_router.dart';
import 'package:mzansi_innovation_hub/mih_package_components/Example/package_tools/package_tool_zero.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_package.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_package_action.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_package_tools.dart';
@@ -59,16 +60,21 @@ class _PackageTestState extends State<PackageTest> {
MihPackageTools getTools() {
Map<Widget, void Function()?> temp = Map();
temp[const Icon(Icons.inbox)] = () {
temp[const Icon(Icons.warning)] = () {
setState(() {
_selcetedIndex = 0;
});
};
temp[const Icon(Icons.outbond)] = () {
temp[const Icon(Icons.inbox)] = () {
setState(() {
_selcetedIndex = 1;
});
};
temp[const Icon(Icons.outbond)] = () {
setState(() {
_selcetedIndex = 2;
});
};
return MihPackageTools(
tools: temp,
selcetedIndex: _selcetedIndex,
@@ -76,13 +82,14 @@ class _PackageTestState extends State<PackageTest> {
}
void showAlert() {
MihAlertServices().inputErrorMessage(context);
MihAlertServices().inputErrorAlert(context);
}
List<Widget> getToolBody() {
MzansiProfileProvider profileProvider =
context.read<MzansiProfileProvider>();
List<Widget> toolBodies = [
const PackageToolZero(),
PackageToolOne(
user: profileProvider.user!,
business: profileProvider.business,
@@ -94,6 +101,7 @@ class _PackageTestState extends State<PackageTest> {
List<String> getToolTitle() {
List<String> toolTitles = [
"Tool Zero",
"Tool One",
"Tool Two",
];

View File

@@ -645,7 +645,7 @@ class _PackageToolOneState extends State<PackageToolOne> {
const SnackBar(content: Text("Input Valid")),
);
} else {
MihAlertServices().inputErrorMessage(context);
MihAlertServices().inputErrorAlert(context);
}
},
buttonColor: MihColors.getSecondaryColor(

View File

@@ -0,0 +1,403 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:mzansi_innovation_hub/main.dart';
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_button.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_package_tool_body.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_single_child_scroll.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_alert_services.dart';
class PackageToolZero extends StatefulWidget {
const PackageToolZero({super.key});
@override
State<PackageToolZero> createState() => _PackageToolZeroState();
}
class _PackageToolZeroState extends State<PackageToolZero> {
@override
Widget build(BuildContext context) {
return MihPackageToolBody(
borderOn: false,
bodyItem: getBody(),
);
}
Widget getBody() {
return MihSingleChildScroll(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
"This is Package Tool Zero to test MIH Alerts",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
),
),
const SizedBox(height: 20),
MihButton(
width: 300,
onPressed: () {
MihAlertServices().successBasicAlert(
"Success!",
"This is the message for the success message",
context,
);
},
buttonColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
child: Text(
"Basic Success Alert",
style: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(height: 10),
MihButton(
width: 300,
onPressed: () {
MihAlertServices().successAdvancedAlert(
"Success!",
"This is the advanced alert message",
[
MihButton(
onPressed: () {
context.pop();
},
buttonColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
width: 300,
elevation: 10,
child: Text(
"Okay",
style: TextStyle(
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
MihButton(
onPressed: () {
context.pop();
},
buttonColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
width: 300,
elevation: 10,
child: Text(
"Dismiss",
style: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
],
context,
);
},
buttonColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
child: Text(
"Advanced Success Alert",
style: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(height: 10),
MihButton(
width: 300,
onPressed: () {
MihAlertServices().warningAlert(
"Warning Alert!", "This is a friendly warning mee", context);
},
buttonColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
child: Text(
"Warning Alert",
style: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(height: 10),
MihButton(
width: 300,
onPressed: () {
MihAlertServices().errorBasicAlert(
"Error!",
"Thisis the basic error alert message",
context,
);
},
buttonColor: MihColors.getRedColor(
MzansiInnovationHub.of(context)!.theme.mode != "Dark"),
child: Text(
"Basic Error Alert",
style: TextStyle(
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(height: 10),
MihButton(
width: 300,
onPressed: () {
MihAlertServices().errorAdvancedAlert(
"Error!",
"This is the advanced alert message",
[
MihButton(
onPressed: () {
context.pop();
},
buttonColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
width: 300,
elevation: 10,
child: Text(
"Okay",
style: TextStyle(
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
MihButton(
onPressed: () {
context.pop();
},
buttonColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
width: 300,
elevation: 10,
child: Text(
"Dismiss",
style: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
],
context,
);
},
buttonColor: MihColors.getRedColor(
MzansiInnovationHub.of(context)!.theme.mode != "Dark"),
child: Text(
"Advanced Error Alert",
style: TextStyle(
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(height: 10),
MihButton(
width: 300,
onPressed: () {
MihAlertServices().deleteConfirmationAlert(
"THis is a delete confirmation",
() {
context.pop();
},
context,
);
},
buttonColor: MihColors.getRedColor(
MzansiInnovationHub.of(context)!.theme.mode != "Dark"),
child: Text(
"Delete Confirmation Alert",
style: TextStyle(
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(height: 10),
MihButton(
width: 300,
onPressed: () {
MihAlertServices().internetConnectionAlert(context);
},
buttonColor: MihColors.getRedColor(
MzansiInnovationHub.of(context)!.theme.mode != "Dark"),
child: Text(
"Internet Connection Alert",
style: TextStyle(
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(height: 10),
MihButton(
width: 300,
onPressed: () {
MihAlertServices().locationPermissionAlert(context);
},
buttonColor: MihColors.getRedColor(
MzansiInnovationHub.of(context)!.theme.mode != "Dark"),
child: Text(
"Location Permission Alert",
style: TextStyle(
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(height: 10),
MihButton(
width: 300,
onPressed: () {
MihAlertServices().inputErrorAlert(context);
},
buttonColor: MihColors.getRedColor(
MzansiInnovationHub.of(context)!.theme.mode != "Dark"),
child: Text(
"Input Error Alert",
style: TextStyle(
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(height: 10),
MihButton(
width: 300,
onPressed: () {
MihAlertServices().passwordRequirementAlert(context);
},
buttonColor: MihColors.getRedColor(
MzansiInnovationHub.of(context)!.theme.mode != "Dark"),
child: FittedBox(
child: Text(
"Password Requirement Alert",
style: TextStyle(
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
),
const SizedBox(height: 10),
MihButton(
width: 300,
onPressed: () {
MihAlertServices().passwordMatchAlert(context);
},
buttonColor: MihColors.getRedColor(
MzansiInnovationHub.of(context)!.theme.mode != "Dark"),
child: Text(
"Password Match Alert",
style: TextStyle(
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(height: 10),
MihButton(
width: 300,
onPressed: () {
MihAlertServices().loginErrorAlert(context);
},
buttonColor: MihColors.getRedColor(
MzansiInnovationHub.of(context)!.theme.mode != "Dark"),
child: Text(
"Login Error Alert",
style: TextStyle(
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(height: 10),
MihButton(
width: 300,
onPressed: () {
MihAlertServices().emailExistsAlert(context);
},
buttonColor: MihColors.getRedColor(
MzansiInnovationHub.of(context)!.theme.mode != "Dark"),
child: Text(
"Email Exists Alert",
style: TextStyle(
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(height: 10),
MihButton(
width: 300,
onPressed: () {
MihAlertServices().invalidEmailAlert(context);
},
buttonColor: MihColors.getRedColor(
MzansiInnovationHub.of(context)!.theme.mode != "Dark"),
child: Text(
"Invalid Email Alert",
style: TextStyle(
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(height: 10),
],
),
);
}
}

View File

@@ -43,7 +43,7 @@ class _MIHNotificationDrawerState extends State<MIHNotificationDrawer> {
arguments: widget.signedInUser,
);
} else {
MihAlertServices().internetConnectionLost(context);
MihAlertServices().internetConnectionAlert(context);
}
}

View File

@@ -1,117 +0,0 @@
import 'package:go_router/go_router.dart';
import 'package:mzansi_innovation_hub/main.dart';
import 'package:flutter/material.dart';
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
class MihPackageAlert extends StatefulWidget {
final Widget alertIcon;
final String alertTitle;
final Widget alertBody;
final Color alertColour;
const MihPackageAlert({
super.key,
required this.alertIcon,
required this.alertTitle,
required this.alertBody,
required this.alertColour,
});
@override
State<MihPackageAlert> createState() => _MihPackageAlertState();
}
class _MihPackageAlertState extends State<MihPackageAlert> {
late double popUpWidth;
late double? popUpheight;
late double popUpTitleSize;
late double popUpSubtitleSize;
late double popUpBodySize;
late double popUpIconSize;
late double popUpPaddingSize;
Size? size;
void checkScreenSize() {
if (MzansiInnovationHub.of(context)!.theme.screenType == "desktop") {
setState(() {
popUpWidth = (size!.width / 4) * 2;
popUpheight = null;
popUpTitleSize = 30.0;
popUpSubtitleSize = 20.0;
popUpBodySize = 15;
popUpPaddingSize = 25.0;
popUpIconSize = 100;
});
} else {
setState(() {
popUpWidth = size!.width - (size!.width * 0.1);
popUpheight = null;
popUpTitleSize = 25.0;
popUpSubtitleSize = 18.0;
popUpBodySize = 15;
popUpPaddingSize = 15.0;
popUpIconSize = 100;
});
}
}
@override
Widget build(BuildContext context) {
size = MediaQuery.of(context).size;
checkScreenSize();
return Dialog(
child: Stack(
children: [
Container(
padding: EdgeInsets.all(popUpPaddingSize),
width: popUpWidth,
height: popUpheight,
decoration: BoxDecoration(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
borderRadius: BorderRadius.circular(25.0),
border: Border.all(color: widget.alertColour, width: 5.0),
),
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
widget.alertIcon,
//const SizedBox(height: 5),
Text(
widget.alertTitle,
textAlign: TextAlign.center,
style: TextStyle(
color: widget.alertColour,
fontSize: popUpTitleSize,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 15),
widget.alertBody,
const SizedBox(height: 10),
],
),
),
),
Positioned(
top: 5,
right: 5,
width: 50,
height: 50,
child: IconButton(
onPressed: () {
context.pop();
},
icon: Icon(
Icons.close,
color: MihColors.getRedColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
size: 35,
),
),
),
],
),
);
}
}

View File

@@ -3,11 +3,11 @@ import 'package:flutter/foundation.dart';
import 'package:local_auth/local_auth.dart';
import 'package:mzansi_innovation_hub/main.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_button.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_package_alert.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_package_window.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_yt_video_player.dart';
import 'package:flutter/material.dart';
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_alert_services.dart';
class MihPackageTile extends StatefulWidget {
final String appName;
@@ -40,6 +40,7 @@ class _MihPackageTileState extends State<MihPackageTile> {
void displayHint() {
if (widget.ytVideoID != null) {
showDialog(
barrierDismissible: false,
context: context,
builder: (context) {
return MihPackageWindow(
@@ -89,82 +90,67 @@ class _MihPackageTileState extends State<MihPackageTile> {
}
void authErrorPopUp() {
Widget alertpopUp = MihPackageAlert(
alertIcon: Icon(
Icons.fingerprint,
color: MihColors.getRedColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
size: 100,
),
alertTitle: "Biometric Authentication Required",
alertBody: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Hi there! To jump into the ${widget.appName} Package, you'll need to authenticate yourself with your devices biometrics, please set up biometric authentication (like fingerprint, face ID, pattern or pin) on your device first.\n\nIf you have already set up biometric authentication, press \"Authenticate now\" to try again or press \"Set Up Authentication\" to go to your device settings.",
MihAlertServices().errorAdvancedAlert(
"Biometric Authentication Required",
"Hi there! To jump into the ${widget.appName} Package, you'll need to authenticate yourself with your devices biometrics, please set up biometric authentication (like fingerprint, face ID, pattern or pin) on your device first.\n\nIf you have already set up biometric authentication, press \"Authenticate now\" to try again or press \"Set Up Authentication\" to go to your device settings.",
[
MihButton(
onPressed: () {
Navigator.of(context).pop();
},
buttonColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
width: 300,
child: Text(
"Dismiss",
style: TextStyle(
fontSize: 15,
color: MihColors.getSecondaryColor(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 20),
Wrap(
runAlignment: WrapAlignment.center,
crossAxisAlignment: WrapCrossAlignment.center,
spacing: 10,
runSpacing: 10,
children: [
MihButton(
onPressed: () {
AppSettings.openAppSettings(
type: AppSettingsType.security,
);
Navigator.of(context).pop();
},
buttonColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
width: 300,
child: Text(
"Set Up Authentication",
style: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
MihButton(
onPressed: () {
Navigator.of(context).pop();
authenticateUser();
},
buttonColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
width: 300,
child: Text(
"Authenticate Now",
style: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
],
),
MihButton(
onPressed: () {
AppSettings.openAppSettings(
type: AppSettingsType.security,
);
Navigator.of(context).pop();
},
buttonColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
width: 300,
child: Text(
"Set Up Authentication",
style: TextStyle(
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
],
),
alertColour: MihColors.getRedColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
);
showDialog(
context: context,
builder: (context) {
return alertpopUp;
},
),
MihButton(
onPressed: () {
Navigator.of(context).pop();
authenticateUser();
},
buttonColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
width: 300,
child: Text(
"Authenticate Now",
style: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
],
context,
);
}