switch to new image api strat and fix onboarding cache strat

This commit is contained in:
yaso 2026-07-07 14:30:58 +02:00
parent 48b434dad9
commit a5bdee892c
39 changed files with 540 additions and 791 deletions

View file

@ -30,8 +30,7 @@ class _MIHAppDrawerState extends State<MIHAppDrawer> {
final proPicController = TextEditingController();
late Widget profilePictureLoaded;
void resetProviders() {
context.read<AboutMihProvider>().reset();
Future<void> clearCacheAndProviders() async {
context.read<MihAccessControllsProvider>().reset();
context.read<MihAuthenticationProvider>().reset();
context.read<MihBannerAdProvider>().reset();
@ -40,8 +39,10 @@ class _MIHAppDrawerState extends State<MIHAppDrawer> {
context.read<MihMineSweeperProvider>().reset();
context.read<MzansiAiProvider>().reset();
context.read<MzansiDirectoryProvider>().reset();
context.read<MzansiWalletProvider>().reset();
context.read<PatientManagerProvider>().reset();
await context.read<AboutMihProvider>().clearAboutMihCacheAndProvider();
await context.read<MzansiWalletProvider>().clearWalletCacheAndProvider();
await context.read<MzansiProfileProvider>().clearProfileCacheAndProvider();
}
Future<bool> signOut() async {
@ -187,32 +188,6 @@ class _MIHAppDrawerState extends State<MIHAppDrawer> {
),
),
),
// ListTile(
// title: Row(
// mainAxisSize: MainAxisSize.max,
// children: [
// Icon(
// Icons.home_outlined,
// color:
// MihColors.secondary(),
// ),
// const SizedBox(width: 25.0),
// Text(
// "Home",
// style: TextStyle(
// //fontWeight: FontWeight.bold,
// color: MzansiInnovationHub.of(context)!
// .theme
// .secondaryColor(),
// ),
// ),
// ],
// ),
// onTap: () {
// Navigator.of(context)
// .pushNamedAndRemoveUntil('/', (route) => false);
// },
// ),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
@ -291,8 +266,7 @@ class _MIHAppDrawerState extends State<MIHAppDrawer> {
});
if (await SuperTokens.doesSessionExist() ==
false) {
resetProviders();
await Future.delayed(Duration.zero);
await clearCacheAndProviders();
if (context.mounted) {
context.goNamed(
'mihHome',
@ -313,21 +287,6 @@ class _MIHAppDrawerState extends State<MIHAppDrawer> {
height: 30,
child: InkWell(
onTap: () {
// setState(() {
// if (MzansiInnovationHub.of(context)?.theme.mode ==
// "Dark") {
// //darkm = !darkm;
// MzansiInnovationHub.of(context)!
// .changeTheme(ThemeMode.light);
// //print("Dark Mode: $darkm");
// } else {
// //darkm = !darkm;
// MzansiInnovationHub.of(context)!
// .changeTheme(ThemeMode.dark);
// //print("Dark Mode: $darkm");
// }
// // Navigator.of(context).popAndPushNamed('/',);
// });
context.goNamed("aboutMih");
},
child: Icon(
@ -335,27 +294,6 @@ class _MIHAppDrawerState extends State<MIHAppDrawer> {
color: MihColors.primary(),
),
),
// IconButton(
// onPressed: () {
// setState(() {
// if (MzansiInnovationHub.of(context)?.theme.mode == "Dark") {
// //darkm = !darkm;
// MzansiInnovationHub.of(context)!.changeTheme(ThemeMode.light);
// //print("Dark Mode: $darkm");
// } else {
// //darkm = !darkm;
// MzansiInnovationHub.of(context)!.changeTheme(ThemeMode.dark);
// //print("Dark Mode: $darkm");
// }
// Navigator.of(context).popAndPushNamed('/');
// });
// },
// icon: Icon(
// Icons.light_mode,
// color: MihColors.primary(),
// size: 35,
// ),
// ),
),
],
);

View file

@ -16,56 +16,55 @@ class MihUserConsentWindow extends StatefulWidget {
}
class _MihUserConsentWindowState extends State<MihUserConsentWindow> {
void createOrUpdateAccpetance(MzansiProfileProvider mzansiProfileProvider) {
void createOrUpdateAccpetance(
MzansiProfileProvider mzansiProfileProvider) async {
UserConsent? userConsent = mzansiProfileProvider.userConsent;
userConsent != null
? MihUserConsentServices()
.updateUserConsentStatus(
DateTime.now().toIso8601String(),
DateTime.now().toIso8601String(),
mzansiProfileProvider,
context,
)
.then((value) {
if (!mounted) return;
if (value == 200) {
context.goNamed("mihHome");
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(
DateTime.now().toIso8601String(),
DateTime.now().toIso8601String(),
mzansiProfileProvider,
context,
)
.then((value) {
if (value == 201) {
context.goNamed("mihHome");
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"),
),
);
}
});
if (userConsent != null) {
MihUserConsentServices()
.updateUserConsentStatus(
DateTime.now().toIso8601String(),
DateTime.now().toIso8601String(),
mzansiProfileProvider,
context,
)
.then((value) {
if (!mounted) return;
if (value == 200) {
context.goNamed("mihHome");
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"),
),
);
}
});
} else {
bool success = await mzansiProfileProvider.addUserConsent(UserConsent(
app_id: mzansiProfileProvider.user!.app_id,
privacy_policy_accepted: DateTime.now(),
terms_of_services_accepted: DateTime.now(),
));
if (success) {
context.pop();
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

View file

@ -45,8 +45,9 @@ class _MihHomeState extends State<MihHome> {
mzansiProfileProvider.loadCachedProfileState();
if (mzansiProfileProvider.user == null) {
await mzansiProfileProvider.syncWithMihServerData();
} else {
mzansiProfileProvider.syncWithMihServerData();
}
if(mzansiProfileProvider.isLocalModificationsPending()){
mzansiProfileProvider.syncWithMihServerData();
}
}

View file

@ -209,15 +209,6 @@ class _MihPersonalHomeState extends State<MihPersonalHome>
void initState() {
super.initState();
searchController.addListener(searchPackage);
MzansiProfileProvider profileProvider =
context.read<MzansiProfileProvider>();
if (profileProvider.user == null || profileProvider.user?.username == "") {
personalPackagesMap = setNerUserPersonalPackage();
autoNavToProfile();
} else {
personalPackagesMap = setPersonalPackagesMap(profileProvider);
}
searchPackage();
}
@override
@ -237,6 +228,14 @@ class _MihPersonalHomeState extends State<MihPersonalHome>
return Consumer2<MzansiProfileProvider, MzansiAiProvider>(
builder: (BuildContext context, MzansiProfileProvider profileProvider,
MzansiAiProvider mzansiAiProvider, Widget? child) {
if (profileProvider.user == null ||
profileProvider.user?.username == "") {
personalPackagesMap = setNerUserPersonalPackage();
autoNavToProfile();
} else {
personalPackagesMap = setPersonalPackagesMap(profileProvider);
}
searchPackage();
return Column(
children: [
Visibility(