NEW: Privacy Policy and TOS Popup

This commit is contained in:
2025-09-30 11:12:58 +02:00
parent 9d807f7d28
commit d7af659b23
10 changed files with 586 additions and 46 deletions

View File

@@ -37,6 +37,8 @@ PODS:
- file_picker (0.0.1):
- DKImagePickerController/PhotoGallery
- Flutter
- file_saver (0.0.1):
- Flutter
- fl_downloader (0.0.1):
- Flutter
- Flutter (1.0.0)
@@ -93,6 +95,7 @@ DEPENDENCIES:
- app_settings (from `.symlinks/plugins/app_settings/ios`)
- device_info_plus (from `.symlinks/plugins/device_info_plus/ios`)
- file_picker (from `.symlinks/plugins/file_picker/ios`)
- file_saver (from `.symlinks/plugins/file_saver/ios`)
- fl_downloader (from `.symlinks/plugins/fl_downloader/ios`)
- Flutter (from `Flutter`)
- flutter_native_splash (from `.symlinks/plugins/flutter_native_splash/ios`)
@@ -128,6 +131,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/device_info_plus/ios"
file_picker:
:path: ".symlinks/plugins/file_picker/ios"
file_saver:
:path: ".symlinks/plugins/file_saver/ios"
fl_downloader:
:path: ".symlinks/plugins/fl_downloader/ios"
Flutter:
@@ -171,6 +176,7 @@ SPEC CHECKSUMS:
DKImagePickerController: 946cec48c7873164274ecc4624d19e3da4c1ef3c
DKPhotoGallery: b3834fecb755ee09a593d7c9e389d8b5d6deed60
file_picker: a0560bc09d61de87f12d246fc47d2119e6ef37be
file_saver: 6cdbcddd690cb02b0c1a0c225b37cd805c2bf8b6
fl_downloader: dc99aa8dd303f862cccb830087f37acc9b0156ee
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
flutter_native_splash: c32d145d68aeda5502d5f543ee38c192065986cf

View File

@@ -0,0 +1,29 @@
class UserConsent {
String app_id;
DateTime privacy_policy_accepted;
DateTime terms_of_services_accepted;
UserConsent({
required this.app_id,
required this.privacy_policy_accepted,
required this.terms_of_services_accepted,
});
factory UserConsent.fromJson(Map<String, dynamic> json) {
return UserConsent(
app_id: json['app_id'],
privacy_policy_accepted: DateTime.parse(json['privacy_policy_accepted']),
terms_of_services_accepted:
DateTime.parse(json['terms_of_services_accepted']),
);
}
Map<String, dynamic> toJson() {
return {
'app_id': app_id,
'privacy_policy_accepted': privacy_policy_accepted.toIso8601String(),
'terms_of_services_accepted':
terms_of_services_accepted.toIso8601String(),
};
}
}

View File

@@ -1,3 +1,4 @@
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';
@@ -99,7 +100,7 @@ class _MihPackageAlertState extends State<MihPackageAlert> {
height: 50,
child: IconButton(
onPressed: () {
Navigator.pop(context);
context.pop();
},
icon: Icon(
Icons.close,

View File

@@ -1,10 +1,17 @@
import 'package:go_router/go_router.dart';
import 'package:ken_logger/ken_logger.dart';
import 'package:mzansi_innovation_hub/main.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_objects/arguments.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_objects/user_consent.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_button.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_action.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_alert.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_tools.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_circle_avatar.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_objects/app_user.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_window.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_scack_bar.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart';
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
import 'package:mzansi_innovation_hub/mih_config/mih_env.dart';
@@ -14,32 +21,13 @@ import 'package:mzansi_innovation_hub/mih_packages/mih_home/package_tools/mih_bu
import 'package:mzansi_innovation_hub/mih_packages/mih_home/package_tools/mih_personal_home.dart';
import 'package:flutter/material.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_service_calls.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_user_consent_services.dart';
// ignore: must_be_immutable
class MihHome extends StatefulWidget {
// final AppUser signedInUser;
// final BusinessUser? businessUser;
// final Business? business;
// final Patient? patient;
// final List<MIHNotification> notifications;
// final ImageProvider<Object>? propicFile;
// final bool isUserNew;
// final bool isBusinessUser;
// final bool isBusinessUserNew;
// final bool isDevActive;
final bool personalSelected;
const MihHome({
super.key,
// required this.signedInUser,
// required this.businessUser,
// required this.business,
// required this.patient,
// required this.notifications,
// required this.propicFile,
// required this.isUserNew,
// required this.isBusinessUser,
// required this.isBusinessUserNew,
// required this.isDevActive,
required this.personalSelected,
});
@@ -52,6 +40,79 @@ class _MihHomeState extends State<MihHome> {
late int _selcetedIndex;
late bool _personalSelected;
late Future<HomeArguments> profileData;
late Future<UserConsent?> futureUserConsent;
bool showUserConsent = false;
DateTime latestPrivacyPolicyDate = DateTime.parse("2024-12-01");
DateTime latestTermOfServiceDate = DateTime.parse("2024-12-01");
bool showPolicyWindow(UserConsent? userConsent) {
if (userConsent == null) {
return true;
} else {
if (userConsent.privacy_policy_accepted
.isAfter(latestPrivacyPolicyDate) &&
userConsent.terms_of_services_accepted
.isAfter(latestTermOfServiceDate)) {
return false;
} else {
return true;
}
}
}
void createOrUpdateAccpetance(UserConsent? userConsent, String app_id) {
userConsent != null
? MihUserConsentServices()
.updateUserConsentStatus(
app_id,
DateTime.now().toIso8601String(),
DateTime.now().toIso8601String(),
)
.then((value) {
if (value == 200) {
// setState(() {
// showUserConsent = false;
// });
context.goNamed("mihHome", extra: false);
ScaffoldMessenger.of(context).showSnackBar(
MihSnackBar(
child: Text("Thank you for accepting our Policies"),
),
);
} else {
ScaffoldMessenger.of(context).showSnackBar(
MihSnackBar(
child: Text("There was an error, please try again later"),
),
);
}
})
: MihUserConsentServices()
.insertUserConsentStatus(
app_id,
DateTime.now().toIso8601String(),
DateTime.now().toIso8601String(),
)
.then((value) {
if (value == 201) {
// setState(() {
// showUserConsent = false;
// });
context.goNamed("mihHome", extra: false);
ScaffoldMessenger.of(context).showSnackBar(
MihSnackBar(
child: Text("Thank you for accepting our Policies"),
),
);
} else {
ScaffoldMessenger.of(context).showSnackBar(
MihSnackBar(
child: Text("There was an error, please try again later"),
),
);
}
});
}
@override
void dispose() {
@@ -62,6 +123,7 @@ class _MihHomeState extends State<MihHome> {
void initState() {
super.initState();
profileData = MIHApiCalls().getProfile(10, context);
futureUserConsent = MihUserConsentServices().getUserConsentStatus();
if (widget.personalSelected == true) {
setState(() {
_selcetedIndex = 0;
@@ -96,30 +158,259 @@ class _MihHomeState extends State<MihHome> {
);
} else if (asyncSnapshot.connectionState == ConnectionState.done &&
asyncSnapshot.hasData) {
return MihPackage(
appActionButton: getAction(asyncSnapshot.data!.profilePicUrl),
appTools:
getTools(asyncSnapshot.data!.signedInUser.type != "personal"),
appBody: getToolBody(asyncSnapshot.data!),
appToolTitles: getToolTitle(),
actionDrawer: getActionDrawer(
asyncSnapshot.data!.signedInUser,
asyncSnapshot.data!.profilePicUrl,
),
selectedbodyIndex: _selcetedIndex,
onIndexChange: (newValue) {
if (_selcetedIndex == 0) {
setState(() {
_selcetedIndex = newValue;
_personalSelected = true;
});
} else {
setState(() {
_selcetedIndex = newValue;
_personalSelected = false;
});
}
},
return Stack(
children: [
MihPackage(
appActionButton: getAction(asyncSnapshot.data!.profilePicUrl),
appTools: getTools(
asyncSnapshot.data!.signedInUser.type != "personal"),
appBody: getToolBody(asyncSnapshot.data!),
appToolTitles: getToolTitle(),
actionDrawer: getActionDrawer(
asyncSnapshot.data!.signedInUser,
asyncSnapshot.data!.profilePicUrl,
),
selectedbodyIndex: _selcetedIndex,
onIndexChange: (newValue) {
if (_selcetedIndex == 0) {
setState(() {
_selcetedIndex = newValue;
_personalSelected = true;
});
} else {
setState(() {
_selcetedIndex = newValue;
_personalSelected = false;
});
}
},
),
FutureBuilder(
future: futureUserConsent,
builder: (context, asyncSnapshotUserConsent) {
if (asyncSnapshotUserConsent.connectionState ==
ConnectionState.waiting) {
showUserConsent = false;
} else if (asyncSnapshotUserConsent.connectionState ==
ConnectionState.done &&
asyncSnapshotUserConsent.hasData) {
showUserConsent =
showPolicyWindow(asyncSnapshotUserConsent.data);
} else if (asyncSnapshotUserConsent.connectionState ==
ConnectionState.done &&
!asyncSnapshotUserConsent.hasData) {
showUserConsent = true;
} else {
showUserConsent = false;
}
return Visibility(
visible: showUserConsent,
child: Container(
color: Colors.black.withValues(alpha: 0.5),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: [
MihPackageWindow(
fullscreen: false,
windowTitle:
"Privacy Policy & Terms Of Service Alert!",
onWindowTapClose: () {
showDialog(
context: context,
builder: (context) {
return MihPackageAlert(
alertIcon: Icon(
Icons.warning_amber_rounded,
size: 100,
color: MihColors.getRedColor(
MzansiInnovationHub.of(context)!
.theme
.mode ==
"Dark",
),
),
alertTitle:
"Oops, Looks like you missed a step!",
alertBody: Text(
"We're excited for you to keep using the MIH app! Before you do, please take a moment to accept our Privacy Policy and Terms of Service. Thanks for helping us keep your experience great!",
textAlign: TextAlign.center,
style: TextStyle(
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!
.theme
.mode ==
"Dark",
),
fontSize: 15,
fontWeight: FontWeight.normal,
),
),
alertColour: MihColors.getRedColor(
MzansiInnovationHub.of(context)!
.theme
.mode ==
"Dark",
),
);
});
},
windowBody: Column(
children: [
Icon(
Icons.policy,
size: 150,
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!
.theme
.mode ==
"Dark",
),
),
const SizedBox(height: 10),
Text(
"Welcome to the MIH App",
textAlign: TextAlign.center,
style: TextStyle(
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!
.theme
.mode ==
"Dark",
),
fontSize: 30,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 10),
Text(
"To keep using the MIH app, please take a moment to review and accept our Privacy Policy and Terms of Service. our agreement helps us keep things running smoothly and securely.",
textAlign: TextAlign.center,
style: TextStyle(
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!
.theme
.mode ==
"Dark",
),
fontSize: 15,
fontWeight: FontWeight.normal,
),
),
const SizedBox(height: 20),
Center(
child: Wrap(
alignment: WrapAlignment.center,
spacing: 10,
runSpacing: 10,
children: [
MihButton(
onPressed: () {
context.goNamed(
"aboutMih",
extra: AboutArguments(
widget.personalSelected,
1,
),
);
},
buttonColor: MihColors.getOrangeColor(
MzansiInnovationHub.of(context)!
.theme
.mode ==
"Dark"),
elevation: 10,
width: 300,
child: Text(
"Privacy Policy",
style: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(
context)!
.theme
.mode ==
"Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
MihButton(
onPressed: () {
context.goNamed(
"aboutMih",
extra: AboutArguments(
widget.personalSelected,
2,
),
);
},
buttonColor: MihColors.getYellowColor(
MzansiInnovationHub.of(context)!
.theme
.mode ==
"Dark"),
elevation: 10,
width: 300,
child: Text(
"Terms of Service",
style: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(
context)!
.theme
.mode ==
"Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
MihButton(
onPressed: () {
DateTime now = DateTime.now();
KenLogger.success(
"Date Time Now: $now");
createOrUpdateAccpetance(
asyncSnapshotUserConsent.data,
asyncSnapshot
.data!.signedInUser.app_id,
);
},
buttonColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!
.theme
.mode ==
"Dark"),
elevation: 10,
width: 300,
child: Text(
"Accept",
style: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(
context)!
.theme
.mode ==
"Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
],
),
),
const SizedBox(height: 10),
],
),
),
],
),
),
);
}),
],
);
} else {
return MihHomeError(

View File

@@ -0,0 +1,57 @@
import 'dart:convert';
import 'package:mzansi_innovation_hub/mih_components/mih_objects/user_consent.dart';
import 'package:mzansi_innovation_hub/mih_config/mih_env.dart';
import 'package:supertokens_flutter/http.dart' as http;
import 'package:supertokens_flutter/supertokens.dart';
class MihUserConsentServices {
Future<UserConsent?> getUserConsentStatus() async {
var app_id = await SuperTokens.getUserId();
final response = await http.get(
Uri.parse("${AppEnviroment.baseApiUrl}/user-consent/user/$app_id"));
if (response.statusCode == 200) {
Map<String, dynamic> userMap = jsonDecode(response.body);
UserConsent userConsent = UserConsent.fromJson(userMap);
return userConsent;
} else {
return null;
}
}
Future<int> insertUserConsentStatus(
String app_id,
String latestPrivacyPolicyDate,
String latestTermOfServiceDate,
) async {
UserConsent userConsent = UserConsent(
app_id: app_id,
privacy_policy_accepted: DateTime.parse(latestPrivacyPolicyDate),
terms_of_services_accepted: DateTime.parse(latestTermOfServiceDate),
);
final response = await http.post(
Uri.parse("${AppEnviroment.baseApiUrl}/user-consent/insert/"),
headers: {"Content-Type": "application/json"},
body: jsonEncode(userConsent.toJson()),
);
return response.statusCode;
}
Future<int> updateUserConsentStatus(
String app_id,
String latestPrivacyPolicyDate,
String latestTermOfServiceDate,
) async {
UserConsent userConsent = UserConsent(
app_id: app_id,
privacy_policy_accepted: DateTime.parse(latestPrivacyPolicyDate),
terms_of_services_accepted: DateTime.parse(latestTermOfServiceDate),
);
final response = await http.put(
Uri.parse("${AppEnviroment.baseApiUrl}/user-consent/update"),
headers: {"Content-Type": "application/json"},
body: jsonEncode(userConsent.toJson()),
);
return response.statusCode;
}
}