switch to new image api strat and fix onboarding cache strat
This commit is contained in:
parent
48b434dad9
commit
a5bdee892c
39 changed files with 540 additions and 791 deletions
|
|
@ -42,6 +42,7 @@ void main() async {
|
|||
await Hive.openBox<ProfileLink>('personal_profile_links_box');
|
||||
await Hive.openBox<ProfileLink>('business_profile_links_box');
|
||||
await Hive.openBox<BusinessEmployee>('business_employees_box');
|
||||
await Hive.openBox<Map>('profile_modifications_queue');
|
||||
// Mzansi Wallet Data
|
||||
await Hive.openBox<MIHLoyaltyCard>('loyalty_card_box');
|
||||
await Hive.openBox<MIHLoyaltyCard>('fav_loyalty_card_box');
|
||||
|
|
|
|||
|
|
@ -9,6 +9,16 @@ class AboutMihHiveData {
|
|||
static const String kUserCountKey = 'current_user_count';
|
||||
static const String kBusinessCountKey = 'current_business_count';
|
||||
|
||||
// Clear Local Cache
|
||||
Future<void> clearAboutMIHCache() async {
|
||||
try {
|
||||
await _mihUserBusinessCountBox.clear();
|
||||
KenLogger.success("Cleared Local About MIH Cache.");
|
||||
} catch (error) {
|
||||
KenLogger.error("Failed to clear local about mih cache.");
|
||||
}
|
||||
}
|
||||
|
||||
// Get Data from local storage
|
||||
int? getcachedUserCount() => _mihUserBusinessCountBox.get(kUserCountKey);
|
||||
int? getcachedBusinessCount() =>
|
||||
|
|
|
|||
|
|
@ -26,6 +26,25 @@ class MzansiProfileHiveData {
|
|||
Hive.box<ProfileLink>('business_profile_links_box');
|
||||
final Box<BusinessEmployee> _businessEmployeesBox =
|
||||
Hive.box<BusinessEmployee>('business_Employees_box');
|
||||
final Box<Map> _modificationsQueue =
|
||||
Hive.box<Map>('profile_modifications_queue');
|
||||
|
||||
// Set offline data
|
||||
Future<void> clearProfileCache() async {
|
||||
try {
|
||||
await _userBox.clear();
|
||||
await _businessBox.clear();
|
||||
await _businessUserBox.clear();
|
||||
await _userConsentBox.clear();
|
||||
await _personalProfileLinksBox.clear();
|
||||
await _businessProfileLinksBox.clear();
|
||||
await _businessEmployeesBox.clear();
|
||||
await _modificationsQueue.clear();
|
||||
KenLogger.success("Cleared Local Profile Cache.");
|
||||
} catch (error) {
|
||||
KenLogger.error("Failed to clear local profile cache.");
|
||||
}
|
||||
}
|
||||
|
||||
static const String kUserKey = 'current_user';
|
||||
static const String kBusinessKey = 'current_business';
|
||||
|
|
@ -144,4 +163,58 @@ class MzansiProfileHiveData {
|
|||
// KenLogger.warning("App operating offline mode. Sync paused: $error");
|
||||
}
|
||||
}
|
||||
|
||||
// Set Offline Data
|
||||
Future<bool> addUserConsentLocally(UserConsent newConsent) async {
|
||||
try {
|
||||
await _userConsentBox.put(kConsentKey, newConsent);
|
||||
KenLogger.success("Consent Saved Locally.");
|
||||
return true;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Modification Processing
|
||||
Future<void> queuAddConsentModification(UserConsent newConsent) async {
|
||||
await _modificationsQueue.add({
|
||||
'action': 'ADD',
|
||||
'type': 'CONSENT',
|
||||
'payload': newConsent,
|
||||
});
|
||||
KenLogger.success("Add Consent Queues for Online Sync");
|
||||
}
|
||||
|
||||
Future<bool> processModificationsQueue() async {
|
||||
if (_modificationsQueue.isEmpty) {
|
||||
return true;
|
||||
}
|
||||
final List<dynamic> queueKeys = _modificationsQueue.keys.toList();
|
||||
for (var taskKey in queueKeys) {
|
||||
final task = _modificationsQueue.get(taskKey);
|
||||
if (task == null) {
|
||||
continue;
|
||||
}
|
||||
final String action = task['action'];
|
||||
final String type = task['type'];
|
||||
if (type == 'CONSENT') {
|
||||
final UserConsent consentTask = task['payload'];
|
||||
if (action == 'ADD') {
|
||||
final responseCode =
|
||||
await MihUserConsentServices().insertUserConsentStatusV2(
|
||||
consentTask,
|
||||
);
|
||||
if (responseCode != null && responseCode == 201) {
|
||||
await _modificationsQueue.delete(taskKey);
|
||||
KenLogger.success("Add User Consent to MIH Server");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool isModificationsNotEmpty() {
|
||||
return _modificationsQueue.values.toList().isNotEmpty;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,18 @@ class MzansiWalletHiveData {
|
|||
final Box<Map> _modificationsQueue =
|
||||
Hive.box<Map>('wallet_modifications_queue');
|
||||
|
||||
// Set offline data
|
||||
Future<void> clearWalletCache() async {
|
||||
try {
|
||||
await _loyaltyCardBox.clear();
|
||||
await _favLoyaltyCardBox.clear();
|
||||
await _modificationsQueue.clear();
|
||||
KenLogger.success("Cleared Local Wallet Cache.");
|
||||
} catch (error) {
|
||||
KenLogger.error("Failed to clear local wallet cache.");
|
||||
}
|
||||
}
|
||||
|
||||
// Get Offline Data
|
||||
List<MIHLoyaltyCard> getCachedLoyaltyCards() {
|
||||
final cards = _loyaltyCardBox.values.toList();
|
||||
|
|
@ -204,8 +216,6 @@ class MzansiWalletHiveData {
|
|||
}
|
||||
final String action = task['action'];
|
||||
final MIHLoyaltyCard taskCard = task['payload'];
|
||||
KenLogger.warning(
|
||||
"Card Details: id=${taskCard.idloyalty_cards}, shop=${taskCard.shop_name}, Nunber=${taskCard.card_number}, offline_id=${taskCard.offline_id}");
|
||||
if (action == 'ADD') {
|
||||
dynamic deleteCardTaskKey;
|
||||
for (var entry in _modificationsQueue.toMap().entries) {
|
||||
|
|
|
|||
|
|
@ -539,7 +539,6 @@ class _MihBusinessCardState extends State<MihBusinessCard> {
|
|||
}
|
||||
directoryProvider.setSearchedBusinesses(
|
||||
searchedBusinesses: businessSearchResults,
|
||||
businessesImagesUrl: busImagesUrl,
|
||||
);
|
||||
setState(() {
|
||||
_businessReviewFuture = getUserReview();
|
||||
|
|
|
|||
|
|
@ -518,15 +518,8 @@ class _MihBusinessCardV2State extends State<MihBusinessCardV2> {
|
|||
businessSearchResults = await MihBusinessDetailsServices()
|
||||
.searchBusinesses(directoryProvider.searchTerm,
|
||||
directoryProvider.businessTypeFilter, context);
|
||||
Map<String, Future<String>> busImagesUrl = {};
|
||||
Future<String> businessLogoUrl;
|
||||
for (var bus in businessSearchResults) {
|
||||
businessLogoUrl = MihFileApi.getMinioFileUrl(bus.logo_path);
|
||||
busImagesUrl[bus.business_id] = businessLogoUrl;
|
||||
}
|
||||
directoryProvider.setSearchedBusinesses(
|
||||
searchedBusinesses: businessSearchResults,
|
||||
businessesImagesUrl: busImagesUrl,
|
||||
);
|
||||
setState(() {
|
||||
_businessReviewFuture = getUserReview();
|
||||
|
|
|
|||
|
|
@ -54,7 +54,8 @@ class _MihBusinessProfilePreviewState extends State<MihBusinessProfilePreview> {
|
|||
size: profilePictureWidth,
|
||||
color: MihColors.secondary(),
|
||||
)
|
||||
: widget.imageFile == null
|
||||
: widget.business.logo_path.endsWith('/') ||
|
||||
widget.business.logo_path == ''
|
||||
? Icon(
|
||||
MihIcons.mihIDontKnow,
|
||||
size: profilePictureWidth,
|
||||
|
|
|
|||
|
|
@ -36,7 +36,8 @@ class _MihPersonalProfilePreviewState extends State<MihPersonalProfilePreview> {
|
|||
size: profilePictureWidth,
|
||||
color: MihColors.secondary(),
|
||||
)
|
||||
: widget.imageFile == null
|
||||
: widget.user.pro_pic_path.endsWith('/') ||
|
||||
widget.user.pro_pic_path == ""
|
||||
? Icon(
|
||||
MihIcons.mihIDontKnow,
|
||||
size: profilePictureWidth,
|
||||
|
|
|
|||
|
|
@ -1,18 +1,13 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:mih_package_toolkit/mih_package_toolkit.dart';
|
||||
import 'package:mzansi_innovation_hub/main.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_providers/mih_authentication_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_providers/mzansi_profile_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_env.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_alert_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_user_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_authentication_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_validation_services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:supertokens_flutter/http.dart' as http;
|
||||
import 'package:supertokens_flutter/supertokens.dart';
|
||||
|
||||
class MihRegister extends StatefulWidget {
|
||||
const MihRegister({
|
||||
|
|
@ -31,142 +26,11 @@ class _MihRegisterState extends State<MihRegister> {
|
|||
final _formKey = GlobalKey<FormState>();
|
||||
final baseAPI = AppEnviroment.baseApiUrl;
|
||||
|
||||
Future<void> addUserAPICall(String email, String uid) async {
|
||||
//await getOfficeIdByUser(docOfficeIdApiUrl + widget.userEmail);
|
||||
//print(futureDocOfficeId.toString());
|
||||
await MihUserServices().createUser(
|
||||
email,
|
||||
uid,
|
||||
context,
|
||||
);
|
||||
// var response = await http.post(
|
||||
// Uri.parse("$baseAPI/user/insert/"),
|
||||
// headers: <String, String>{
|
||||
// "Content-Type": "application/json; charset=UTF-8"
|
||||
// },
|
||||
// body: jsonEncode(<String, dynamic>{
|
||||
// "email": email,
|
||||
// "app_id": uid,
|
||||
// }),
|
||||
// );
|
||||
// if (response.statusCode == 201) {
|
||||
// Navigator.of(context).pushNamedAndRemoveUntil(
|
||||
// '/',
|
||||
// (route) => false,
|
||||
// arguments: AuthArguments(
|
||||
// true,
|
||||
// true,
|
||||
// ),
|
||||
// );
|
||||
// // signUpSuccess();
|
||||
// // setState(() {
|
||||
// // successfulSignUp = true;
|
||||
// // });
|
||||
// } else {
|
||||
// internetConnectionPopUp();
|
||||
// }
|
||||
}
|
||||
|
||||
Future<void> signUserUp() async {
|
||||
context.read<MzansiProfileProvider>().reset();
|
||||
if (!validEmail()) {
|
||||
MihAlertServices().invalidEmailAlert(context);
|
||||
} else if (passwordController.text != confirmPasswordController.text) {
|
||||
MihAlertServices().passwordMatchAlert(context);
|
||||
} else {
|
||||
//var _backgroundColor = Colors.transparent;
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return const Mihloadingcircle();
|
||||
},
|
||||
);
|
||||
try {
|
||||
Uri uri = Uri.parse(
|
||||
"$baseAPI/auth/emailpassword/email/exists?email=${emailController.text}");
|
||||
//print("Here");
|
||||
var response = await http.get(uri);
|
||||
//print(response.body);
|
||||
//print("response 1: ${response.statusCode}");
|
||||
if (response.statusCode == 200) {
|
||||
var userExists = jsonDecode(response.body);
|
||||
if (userExists["exists"]) {
|
||||
Navigator.of(context).pop();
|
||||
MihAlertServices().emailExistsAlert(context);
|
||||
} else {
|
||||
var response2 = await http.post(
|
||||
Uri.parse("$baseAPI/auth/signup"),
|
||||
body:
|
||||
'{"formFields": [{"id": "email","value": "${emailController.text}"}, {"id": "password","value": "${passwordController.text}"}]}',
|
||||
headers: {
|
||||
'Content-type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
},
|
||||
);
|
||||
//print("response 2: ${response2.statusCode}");
|
||||
if (response2.statusCode == 200) {
|
||||
//print("response 2: ${response2.body}");
|
||||
var userCreated = jsonDecode(response2.body);
|
||||
//print("Created user $userCreated");
|
||||
if (userCreated["status"] == "OK") {
|
||||
//print("Here1");
|
||||
//Creat user in db
|
||||
String uid = await SuperTokens.getUserId();
|
||||
//print("uid: $uid");
|
||||
addUserAPICall(emailController.text, uid);
|
||||
Navigator.of(context).pop();
|
||||
//print("Here1");
|
||||
} else if (userCreated["status"] == "FIELD_ERROR") {
|
||||
Navigator.of(context).pop();
|
||||
MihAlertServices().passwordRequirementAlert(context);
|
||||
} else {
|
||||
Navigator.of(context).pop();
|
||||
MihAlertServices().internetConnectionAlert(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} on Exception catch (error) {
|
||||
Navigator.of(context).pop();
|
||||
loginError(error.toString());
|
||||
emailController.clear();
|
||||
passwordController.clear();
|
||||
confirmPasswordController.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void submitFormInput() async {
|
||||
await signUserUp();
|
||||
}
|
||||
|
||||
bool validEmail() {
|
||||
String text = emailController.text;
|
||||
var regex = RegExp(r'^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$');
|
||||
return regex.hasMatch(text);
|
||||
}
|
||||
|
||||
void loginError(error) {
|
||||
MihAlertServices().errorAdvancedAlert(
|
||||
"Sign Up Error",
|
||||
"An error occurred while signing up: $error Please try again later.",
|
||||
[
|
||||
MihButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
buttonColor: MihColors.secondary(),
|
||||
width: 200,
|
||||
child: Text(
|
||||
"Dismiss",
|
||||
style: TextStyle(
|
||||
color: MihColors.primary(),
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
await MihAuthenticationServices().signUserUp(
|
||||
emailController.text,
|
||||
passwordController.text,
|
||||
confirmPasswordController.text,
|
||||
context,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
// ),
|
||||
// ),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import 'package:mih_package_toolkit/mih_package_toolkit.dart';
|
|||
import 'package:mzansi_innovation_hub/mih_package_components/mih_circle_avatar.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_providers/mih_mine_sweeper_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_providers/mzansi_profile_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_file_services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class BuildMinesweeperLeaderboardList extends StatefulWidget {
|
||||
|
|
@ -43,89 +44,69 @@ class _BuildMinesweeperLeaderboardListState
|
|||
},
|
||||
itemCount: mineSweeperProvider.leaderboard!.length,
|
||||
itemBuilder: (context, index) {
|
||||
return FutureBuilder(
|
||||
future: mineSweeperProvider.leaderboardUserPicturesUrl[index],
|
||||
builder: (context, asyncSnapshot) {
|
||||
ImageProvider<Object>? imageFile;
|
||||
bool loading = true;
|
||||
if (asyncSnapshot.connectionState == ConnectionState.done) {
|
||||
loading = false;
|
||||
if (asyncSnapshot.hasData) {
|
||||
imageFile = asyncSnapshot.requireData != ""
|
||||
? CachedNetworkImageProvider(
|
||||
asyncSnapshot.requireData)
|
||||
: null;
|
||||
} else {
|
||||
imageFile = null;
|
||||
}
|
||||
} else {
|
||||
imageFile = null;
|
||||
}
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: width / 20),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
"#${index + 1}",
|
||||
style: TextStyle(
|
||||
fontSize: 25,
|
||||
color: getMedalColor(index),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
loading
|
||||
? Icon(
|
||||
MihIcons.mihRing,
|
||||
size: 80,
|
||||
color: MihColors.secondary(),
|
||||
)
|
||||
: imageFile == null
|
||||
? Icon(
|
||||
MihIcons.mihIDontKnow,
|
||||
size: 80,
|
||||
color: MihColors.secondary(),
|
||||
)
|
||||
: MihCircleAvatar(
|
||||
key: UniqueKey(),
|
||||
imageFile: imageFile,
|
||||
width: 80,
|
||||
expandable: true,
|
||||
editable: false,
|
||||
fileNameController: null,
|
||||
userSelectedfile: null,
|
||||
frameColor: getMedalColor(index),
|
||||
backgroundColor: MihColors.primary(),
|
||||
onChange: () {},
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
"${mineSweeperProvider.leaderboard![index].username}${profileProvider.user!.username == mineSweeperProvider.leaderboard![index].username ? " (You)" : ""}",
|
||||
textAlign: TextAlign.left,
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: getMedalColor(index),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
"Score: ${mineSweeperProvider.leaderboard![index].game_score}\nTime: ${mineSweeperProvider.leaderboard![index].game_time}",
|
||||
textAlign: TextAlign.left,
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
// fontWeight: FontWeight.bold,
|
||||
color: getMedalColor(index),
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: width / 20),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
"#${index + 1}",
|
||||
style: TextStyle(
|
||||
fontSize: 25,
|
||||
color: getMedalColor(index),
|
||||
),
|
||||
);
|
||||
});
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
mineSweeperProvider.leaderboard![index].proPicUrl
|
||||
.endsWith('/') ||
|
||||
mineSweeperProvider.leaderboard![index].proPicUrl ==
|
||||
''
|
||||
? Icon(
|
||||
MihIcons.mihIDontKnow,
|
||||
size: 80,
|
||||
color: MihColors.secondary(),
|
||||
)
|
||||
: MihCircleAvatar(
|
||||
key: UniqueKey(),
|
||||
imageFile: CachedNetworkImageProvider(
|
||||
MihFileApi.getMinioFileUrlV2(mineSweeperProvider
|
||||
.leaderboard![index].proPicUrl)),
|
||||
width: 80,
|
||||
expandable: true,
|
||||
editable: false,
|
||||
fileNameController: null,
|
||||
userSelectedfile: null,
|
||||
frameColor: getMedalColor(index),
|
||||
backgroundColor: MihColors.primary(),
|
||||
onChange: () {},
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
"${mineSweeperProvider.leaderboard![index].username}${profileProvider.user!.username == mineSweeperProvider.leaderboard![index].username ? " (You)" : ""}",
|
||||
textAlign: TextAlign.left,
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: getMedalColor(index),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
"Score: ${mineSweeperProvider.leaderboard![index].game_score}\nTime: ${mineSweeperProvider.leaderboard![index].game_time}",
|
||||
textAlign: TextAlign.left,
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
// fontWeight: FontWeight.bold,
|
||||
color: getMedalColor(index),
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,10 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:ken_logger/ken_logger.dart';
|
||||
import 'package:mih_package_toolkit/mih_package_toolkit.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_providers/mih_mine_sweeper_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_packages/mine_sweeper/builders/build_minesweeper_leaderboard_list.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_file_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_minesweeper_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_validation_services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
|
@ -24,16 +21,7 @@ class _MihMineSweeperLeaderBoardState extends State<MihMineSweeperLeaderBoard> {
|
|||
MihMineSweeperProvider mineSweeperProvider =
|
||||
context.read<MihMineSweeperProvider>();
|
||||
filterController.text = mineSweeperProvider.difficulty;
|
||||
KenLogger.success("getting data");
|
||||
await MihMinesweeperServices().getTop20Leaderboard(mineSweeperProvider);
|
||||
List<Future<String>> userPicturesUrl = [];
|
||||
Future<String> userPicUrl;
|
||||
for (final ranking in mineSweeperProvider.leaderboard!) {
|
||||
userPicUrl = MihFileApi.getMinioFileUrl(ranking.proPicUrl);
|
||||
userPicturesUrl.add(userPicUrl);
|
||||
}
|
||||
mineSweeperProvider.setLeaderboardUserPictures(
|
||||
leaderboardUserPicturesUrl: userPicturesUrl);
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -26,10 +26,8 @@ class _MihMineSweeperLeaderBoardState extends State<MyScoreBoard> {
|
|||
MihMineSweeperProvider mineSweeperProvider =
|
||||
context.read<MihMineSweeperProvider>();
|
||||
filterController.text = mineSweeperProvider.difficulty;
|
||||
KenLogger.success("getting data");
|
||||
await MihMinesweeperServices()
|
||||
.getMyScoreboard(profileProvider, mineSweeperProvider);
|
||||
KenLogger.success("${mineSweeperProvider.myScoreboard}");
|
||||
}
|
||||
|
||||
void refreshLeaderBoard(
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import 'package:mih_package_toolkit/mih_package_toolkit.dart';
|
|||
import 'package:mzansi_innovation_hub/mih_objects/business.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_business_profile_preview.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_providers/mzansi_directory_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_file_services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class BuildBusinessSearchResultsList extends StatefulWidget {
|
||||
|
|
@ -27,8 +28,6 @@ class _BuildBusinessSearchResultsListState
|
|||
builder: (BuildContext context, MzansiDirectoryProvider directoryProvider,
|
||||
Widget? child) {
|
||||
return ListView.separated(
|
||||
// shrinkWrap: true,
|
||||
// physics: const NeverScrollableScrollPhysics(),
|
||||
itemCount: widget.businessList.length,
|
||||
separatorBuilder: (BuildContext context, index) {
|
||||
return Divider(
|
||||
|
|
@ -54,32 +53,14 @@ class _BuildBusinessSearchResultsListState
|
|||
// vertical: 5,
|
||||
horizontal: 25,
|
||||
),
|
||||
child: FutureBuilder(
|
||||
future: directoryProvider.busSearchImagesUrl![
|
||||
widget.businessList[index].business_id],
|
||||
builder: (context, asyncSnapshot) {
|
||||
ImageProvider<Object>? imageFile;
|
||||
bool loading = true;
|
||||
if (asyncSnapshot.connectionState ==
|
||||
ConnectionState.done) {
|
||||
loading = false;
|
||||
if (asyncSnapshot.hasData) {
|
||||
imageFile = asyncSnapshot.requireData != ""
|
||||
? CachedNetworkImageProvider(
|
||||
asyncSnapshot.requireData)
|
||||
: null;
|
||||
} else {
|
||||
imageFile = null;
|
||||
}
|
||||
} else {
|
||||
imageFile = null;
|
||||
}
|
||||
return MihBusinessProfilePreview(
|
||||
business: widget.businessList[index],
|
||||
imageFile: imageFile,
|
||||
loading: loading,
|
||||
);
|
||||
}),
|
||||
child: MihBusinessProfilePreview(
|
||||
business: widget.businessList[index],
|
||||
imageFile: CachedNetworkImageProvider(
|
||||
MihFileApi.getMinioFileUrlV2(
|
||||
widget.businessList[index].logo_path),
|
||||
),
|
||||
loading: false,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import 'package:mih_package_toolkit/mih_package_toolkit.dart';
|
|||
import 'package:mzansi_innovation_hub/mih_objects/business.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_business_profile_preview.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_providers/mzansi_directory_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_file_services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class BuildFavouriteBusinessesList extends StatefulWidget {
|
||||
|
|
@ -59,32 +60,15 @@ class _BuildFavouriteBusinessesListState
|
|||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 25,
|
||||
),
|
||||
child: FutureBuilder(
|
||||
future: directoryProvider.favBusImagesUrl![
|
||||
widget.favouriteBusinesses[index]!.business_id],
|
||||
builder: (context, asyncSnapshot) {
|
||||
ImageProvider<Object>? imageFile;
|
||||
bool loading = true;
|
||||
if (asyncSnapshot.connectionState ==
|
||||
ConnectionState.done) {
|
||||
loading = false;
|
||||
if (asyncSnapshot.hasData) {
|
||||
imageFile = asyncSnapshot.requireData != ""
|
||||
? CachedNetworkImageProvider(
|
||||
asyncSnapshot.requireData)
|
||||
: null;
|
||||
} else {
|
||||
imageFile = null;
|
||||
}
|
||||
} else {
|
||||
imageFile = null;
|
||||
}
|
||||
return MihBusinessProfilePreview(
|
||||
business: widget.favouriteBusinesses[index]!,
|
||||
imageFile: imageFile,
|
||||
loading: loading,
|
||||
);
|
||||
}),
|
||||
child: MihBusinessProfilePreview(
|
||||
business: widget.favouriteBusinesses[index]!,
|
||||
imageFile: CachedNetworkImageProvider(
|
||||
MihFileApi.getMinioFileUrlV2(
|
||||
widget.favouriteBusinesses[index]!.logo_path,
|
||||
),
|
||||
),
|
||||
loading: false,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import 'package:mih_package_toolkit/mih_package_toolkit.dart';
|
|||
import 'package:mzansi_innovation_hub/mih_objects/app_user.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_personal_profile_preview.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_providers/mzansi_directory_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_file_services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class BuildUserSearchResultsList extends StatefulWidget {
|
||||
|
|
@ -27,8 +28,6 @@ class _BuildUserSearchResultsListState
|
|||
builder: (BuildContext context, MzansiDirectoryProvider directoryProvider,
|
||||
Widget? child) {
|
||||
return ListView.separated(
|
||||
// shrinkWrap: true,
|
||||
// physics: const NeverScrollableScrollPhysics(),
|
||||
itemCount: widget.userList.length,
|
||||
separatorBuilder: (BuildContext context, index) {
|
||||
return Divider(
|
||||
|
|
@ -53,32 +52,14 @@ class _BuildUserSearchResultsListState
|
|||
// vertical: 5,
|
||||
horizontal: 25,
|
||||
),
|
||||
child: FutureBuilder(
|
||||
future: directoryProvider
|
||||
.userSearchImagesUrl![widget.userList[index].app_id],
|
||||
builder: (context, asyncSnapshot) {
|
||||
ImageProvider<Object>? imageFile;
|
||||
bool loading = true;
|
||||
if (asyncSnapshot.connectionState ==
|
||||
ConnectionState.done) {
|
||||
loading = false;
|
||||
if (asyncSnapshot.hasData) {
|
||||
imageFile = asyncSnapshot.requireData != ""
|
||||
? CachedNetworkImageProvider(
|
||||
asyncSnapshot.requireData)
|
||||
: null;
|
||||
} else {
|
||||
imageFile = null;
|
||||
}
|
||||
} else {
|
||||
imageFile = null;
|
||||
}
|
||||
return MihPersonalProfilePreview(
|
||||
user: widget.userList[index],
|
||||
imageFile: imageFile,
|
||||
loading: loading,
|
||||
);
|
||||
}),
|
||||
child: MihPersonalProfilePreview(
|
||||
user: widget.userList[index],
|
||||
imageFile: CachedNetworkImageProvider(
|
||||
MihFileApi.getMinioFileUrlV2(
|
||||
widget.userList[index].pro_pic_path),
|
||||
),
|
||||
loading: false,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import 'package:mzansi_innovation_hub/mih_providers/mzansi_directory_provider.da
|
|||
import 'package:mzansi_innovation_hub/mih_packages/mzansi_directory/builders/build_favourite_businesses_list.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_providers/mzansi_profile_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_business_details_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_file_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_mzansi_directory_services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
|
|
@ -37,20 +36,15 @@ class _MihFavouriteBusinessesState extends State<MihFavouriteBusinesses> {
|
|||
directoryProvider,
|
||||
);
|
||||
List<Business> favBus = [];
|
||||
Map<String, Future<String>> favBusImages = {};
|
||||
Future<String> businessLogoUrl;
|
||||
for (var bus in directoryProvider.bookmarkedBusinesses) {
|
||||
await MihBusinessDetailsServices()
|
||||
.getBusinessDetailsByBusinessId(bus.business_id)
|
||||
.then((business) async {
|
||||
favBus.add(business!);
|
||||
businessLogoUrl = MihFileApi.getMinioFileUrl(business.logo_path);
|
||||
favBusImages[business.business_id] = businessLogoUrl;
|
||||
});
|
||||
}
|
||||
directoryProvider.setFavouriteBusinesses(
|
||||
businesses: favBus,
|
||||
businessesImagesUrl: favBusImages,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:ken_logger/ken_logger.dart';
|
||||
import 'package:mih_package_toolkit/mih_package_toolkit.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/app_user.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/business.dart';
|
||||
|
|
@ -9,7 +8,6 @@ import 'package:mzansi_innovation_hub/mih_packages/mzansi_directory/builders/bui
|
|||
import 'package:mzansi_innovation_hub/mih_packages/mzansi_directory/builders/build_user_search_results_list.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_alert_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_business_details_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_file_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_user_services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
|
|
@ -26,8 +24,6 @@ class _MihSearchMzansiState extends State<MihSearchMzansi> {
|
|||
final TextEditingController mzansiSearchController = TextEditingController();
|
||||
final TextEditingController businessTypeController = TextEditingController();
|
||||
final FocusNode searchFocusNode = FocusNode();
|
||||
// late bool userSearch;
|
||||
// Future<List<AppUser>?> futureUserSearchResults = Future.value();
|
||||
List<AppUser> userSearchResults = [];
|
||||
List<Business> businessSearchResults = [];
|
||||
late Future<List<String>> availableBusinessTypes;
|
||||
|
|
@ -51,9 +47,8 @@ class _MihSearchMzansiState extends State<MihSearchMzansi> {
|
|||
}
|
||||
|
||||
void clearAll(MzansiDirectoryProvider directoryProvider) {
|
||||
directoryProvider
|
||||
.setSearchedBusinesses(searchedBusinesses: [], businessesImagesUrl: {});
|
||||
directoryProvider.setSearchedUsers(searchedUsers: [], userImagesUrl: {});
|
||||
directoryProvider.setSearchedBusinesses(searchedBusinesses: []);
|
||||
directoryProvider.setSearchedUsers(searchedUsers: []);
|
||||
directoryProvider.setSearchTerm(searchTerm: "");
|
||||
setState(() {
|
||||
mzansiSearchController.clear();
|
||||
|
|
@ -73,19 +68,8 @@ class _MihSearchMzansiState extends State<MihSearchMzansi> {
|
|||
directoryProvider.searchTerm.isNotEmpty) {
|
||||
final userResults = await MihUserServices()
|
||||
.searchUsers(profileProvider, directoryProvider.searchTerm, context);
|
||||
Map<String, Future<String>> userImages = {};
|
||||
Future<String> usernProPicUrl;
|
||||
for (var user in userResults) {
|
||||
usernProPicUrl = MihFileApi.getMinioFileUrl(user.pro_pic_path);
|
||||
userImages[user.app_id] = usernProPicUrl;
|
||||
// != ""
|
||||
// ? CachedNetworkImageProvider(usernProPicUrl)
|
||||
// : null;
|
||||
}
|
||||
|
||||
directoryProvider.setSearchedUsers(
|
||||
searchedUsers: userResults,
|
||||
userImagesUrl: userImages,
|
||||
);
|
||||
} else {
|
||||
List<Business>? businessSearchResults = [];
|
||||
|
|
@ -98,18 +82,8 @@ class _MihSearchMzansiState extends State<MihSearchMzansi> {
|
|||
.searchBusinesses(directoryProvider.searchTerm,
|
||||
directoryProvider.businessTypeFilter, context);
|
||||
}
|
||||
Map<String, Future<String>> busImagesUrl = {};
|
||||
Future<String> businessLogoUrl;
|
||||
for (var bus in businessSearchResults) {
|
||||
businessLogoUrl = MihFileApi.getMinioFileUrl(bus.logo_path);
|
||||
busImagesUrl[bus.business_id] = businessLogoUrl;
|
||||
// != ""
|
||||
// ? CachedNetworkImageProvider(businessLogoUrl)
|
||||
// : null;
|
||||
}
|
||||
directoryProvider.setSearchedBusinesses(
|
||||
searchedBusinesses: businessSearchResults,
|
||||
businessesImagesUrl: busImagesUrl,
|
||||
);
|
||||
}
|
||||
setState(() {
|
||||
|
|
|
|||
|
|
@ -47,7 +47,6 @@ class _MihAddBookmarkAlertState extends State<MihAddBookmarkAlert> {
|
|||
}
|
||||
directoryProvider.setFavouriteBusinesses(
|
||||
businesses: favBus,
|
||||
businessesImagesUrl: favBusImages,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,6 @@ class _MihDeleteBookmarkAlertState extends State<MihDeleteBookmarkAlert> {
|
|||
}
|
||||
directoryProvider.setFavouriteBusinesses(
|
||||
businesses: favBus,
|
||||
businessesImagesUrl: favBusImages,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -69,58 +69,20 @@ class _MihBusinessDetailsViewState extends State<MihBusinessDetailsView> {
|
|||
: EdgeInsets.symmetric(horizontal: width * 0),
|
||||
child: Column(
|
||||
children: [
|
||||
FutureBuilder(
|
||||
future: futureImageUrl,
|
||||
builder: (context, asyncSnapshot) {
|
||||
if (asyncSnapshot.connectionState ==
|
||||
ConnectionState.done &&
|
||||
asyncSnapshot.hasData) {
|
||||
if (asyncSnapshot.requireData != "") {
|
||||
return MihCircleAvatar(
|
||||
imageFile: CachedNetworkImageProvider(
|
||||
asyncSnapshot.requireData),
|
||||
width: profilePictureWidth,
|
||||
expandable: true,
|
||||
editable: false,
|
||||
fileNameController: TextEditingController(),
|
||||
userSelectedfile: file,
|
||||
frameColor: MihColors.secondary(),
|
||||
backgroundColor: MihColors.primary(),
|
||||
onChange: () {},
|
||||
);
|
||||
} else {
|
||||
return Icon(
|
||||
MihIcons.mihIDontKnow,
|
||||
size: profilePictureWidth,
|
||||
color: MihColors.secondary(),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return Icon(
|
||||
MihIcons.mihRing,
|
||||
size: profilePictureWidth,
|
||||
color: MihColors.secondary(),
|
||||
);
|
||||
}
|
||||
}),
|
||||
// Center(
|
||||
// child: MihCircleAvatar(
|
||||
// imageFile: widget.logoImage,
|
||||
// width: 150,
|
||||
// editable: false,
|
||||
// fileNameController: fileNameController,
|
||||
// userSelectedfile: imageFile,
|
||||
// frameColor:
|
||||
// MihColors.secondary(),
|
||||
// backgroundColor:
|
||||
// MihColors.primary(),
|
||||
// onChange: (selectedfile) {
|
||||
// setState(() {
|
||||
// imageFile = selectedfile;
|
||||
// });
|
||||
// },
|
||||
// ),
|
||||
// ),
|
||||
MihCircleAvatar(
|
||||
imageFile: CachedNetworkImageProvider(
|
||||
MihFileApi.getMinioFileUrlV2(
|
||||
directoryProvider.selectedBusiness!.logo_path),
|
||||
),
|
||||
width: profilePictureWidth,
|
||||
expandable: true,
|
||||
editable: false,
|
||||
fileNameController: TextEditingController(),
|
||||
userSelectedfile: file,
|
||||
frameColor: MihColors.secondary(),
|
||||
backgroundColor: MihColors.primary(),
|
||||
onChange: () {},
|
||||
),
|
||||
FittedBox(
|
||||
child: Text(
|
||||
directoryProvider.selectedBusiness!.Name,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:file_saver/file_saver.dart';
|
||||
|
|
@ -59,7 +57,7 @@ class _MihBusinessQrCodeState extends State<MihBusinessQrCode> {
|
|||
String encodedData =
|
||||
Uri.encodeComponent("$qrCodedata${business.business_id}");
|
||||
|
||||
return "https://api.qrserver.com/v1/create-qr-code/?data=$encodedData&size=${qrSize}x${qrSize}&bgcolor=$bgColor&color=$color";
|
||||
return "https://api.qrserver.com/v1/create-qr-code/?data=$encodedData&size=${qrSize}x$qrSize&bgcolor=$bgColor&color=$color";
|
||||
}
|
||||
|
||||
Future<void> saveImage(Uint8List imageBytes) async {
|
||||
|
|
@ -206,41 +204,18 @@ class _MihBusinessQrCodeState extends State<MihBusinessQrCode> {
|
|||
backgroundColor: MihColors.secondary(),
|
||||
onChange: () {},
|
||||
)
|
||||
: FutureBuilder(
|
||||
future: futureImageUrl,
|
||||
builder: (context, asyncSnapshot) {
|
||||
if (asyncSnapshot.connectionState ==
|
||||
ConnectionState.done &&
|
||||
asyncSnapshot.hasData) {
|
||||
if (asyncSnapshot.requireData != "" ||
|
||||
asyncSnapshot.requireData.isNotEmpty) {
|
||||
return MihCircleAvatar(
|
||||
imageFile: CachedNetworkImageProvider(
|
||||
asyncSnapshot.requireData),
|
||||
width: profilePictureWidth,
|
||||
expandable: true,
|
||||
editable: false,
|
||||
fileNameController: TextEditingController(),
|
||||
userSelectedfile: file,
|
||||
frameColor: MihColors.primary(),
|
||||
backgroundColor: MihColors.secondary(),
|
||||
onChange: () {},
|
||||
);
|
||||
} else {
|
||||
return Icon(
|
||||
MihIcons.mihIDontKnow,
|
||||
size: profilePictureWidth,
|
||||
color: MihColors.primary(),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return Icon(
|
||||
MihIcons.mihRing,
|
||||
size: profilePictureWidth,
|
||||
color: MihColors.primary(),
|
||||
);
|
||||
}
|
||||
},
|
||||
: MihCircleAvatar(
|
||||
imageFile: CachedNetworkImageProvider(
|
||||
MihFileApi.getMinioFileUrlV2(business.logo_path),
|
||||
),
|
||||
width: profilePictureWidth,
|
||||
expandable: true,
|
||||
editable: false,
|
||||
fileNameController: TextEditingController(),
|
||||
userSelectedfile: file,
|
||||
frameColor: MihColors.primary(),
|
||||
backgroundColor: MihColors.secondary(),
|
||||
onChange: () {},
|
||||
),
|
||||
FittedBox(
|
||||
child: Text(
|
||||
|
|
|
|||
|
|
@ -86,12 +86,9 @@ class _MihEditPersonalProfileWindowState
|
|||
);
|
||||
if (responseCode == 200) {
|
||||
setState(() {
|
||||
setProfileVariables(mzansiProfileProvider);
|
||||
newSelectedProPic = null;
|
||||
});
|
||||
// if (originalProfileTypeIsBusiness == false && businessUser == true) {
|
||||
// stayOnPersonalSide = false;
|
||||
// }
|
||||
await mzansiProfileProvider.syncWithMihServerData();
|
||||
String message = "Your information has been updated successfully!";
|
||||
successPopUp(
|
||||
mzansiProfileProvider,
|
||||
|
|
|
|||
|
|
@ -174,35 +174,67 @@ class _MihPersonalProfileState extends State<MihPersonalProfile> {
|
|||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
MihButton(
|
||||
onPressed: () {
|
||||
addProfileLinksWindow();
|
||||
},
|
||||
buttonColor: MihColors.green(),
|
||||
width: mzansiProfileProvider.personalLinks.isNotEmpty
|
||||
? 50
|
||||
: null,
|
||||
height: 50,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.add,
|
||||
color: MihColors.primary(),
|
||||
),
|
||||
if (mzansiProfileProvider.personalLinks.isEmpty)
|
||||
Text(
|
||||
"Add Links",
|
||||
style: TextStyle(
|
||||
color: MihColors.primary(),
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
mzansiProfileProvider.user!.username != ""
|
||||
? MihButton(
|
||||
onPressed: () {
|
||||
addProfileLinksWindow();
|
||||
},
|
||||
buttonColor: MihColors.green(),
|
||||
width:
|
||||
mzansiProfileProvider.personalLinks.isNotEmpty
|
||||
? 50
|
||||
: null,
|
||||
height: 50,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.add,
|
||||
color: MihColors.primary(),
|
||||
),
|
||||
if (mzansiProfileProvider
|
||||
.personalLinks.isEmpty)
|
||||
Text(
|
||||
"Add Links",
|
||||
style: TextStyle(
|
||||
color: MihColors.primary(),
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
: MihButton(
|
||||
onPressed: () {
|
||||
editProfileWindow();
|
||||
},
|
||||
buttonColor: MihColors.green(),
|
||||
width: null,
|
||||
height: 50,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.edit,
|
||||
color: MihColors.primary(),
|
||||
),
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
Text(
|
||||
"Add Profile",
|
||||
style: TextStyle(
|
||||
color: MihColors.primary(),
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8.0),
|
||||
if (mzansiProfileProvider.personalLinks.isNotEmpty)
|
||||
MihButton(
|
||||
|
|
|
|||
|
|
@ -75,40 +75,21 @@ class _MihPersonalProfileViewState extends State<MihPersonalProfileView> {
|
|||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
FutureBuilder(
|
||||
future: futureImageUrl,
|
||||
builder: (context, asyncSnapshot) {
|
||||
if (asyncSnapshot.connectionState ==
|
||||
ConnectionState.done &&
|
||||
asyncSnapshot.hasData) {
|
||||
if (asyncSnapshot.requireData != "") {
|
||||
return MihCircleAvatar(
|
||||
imageFile: CachedNetworkImageProvider(
|
||||
asyncSnapshot.requireData),
|
||||
width: profilePictureWidth,
|
||||
expandable: true,
|
||||
editable: false,
|
||||
fileNameController: TextEditingController(),
|
||||
userSelectedfile: file,
|
||||
frameColor: MihColors.secondary(),
|
||||
backgroundColor: MihColors.primary(),
|
||||
onChange: () {},
|
||||
);
|
||||
} else {
|
||||
return Icon(
|
||||
MihIcons.mihIDontKnow,
|
||||
size: profilePictureWidth,
|
||||
color: MihColors.secondary(),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return Icon(
|
||||
MihIcons.mihRing,
|
||||
size: profilePictureWidth,
|
||||
color: MihColors.secondary(),
|
||||
);
|
||||
}
|
||||
}),
|
||||
MihCircleAvatar(
|
||||
imageFile: CachedNetworkImageProvider(
|
||||
MihFileApi.getMinioFileUrlV2(
|
||||
directoryProvider.selectedUser!.pro_pic_path,
|
||||
),
|
||||
),
|
||||
width: profilePictureWidth,
|
||||
expandable: true,
|
||||
editable: false,
|
||||
fileNameController: TextEditingController(),
|
||||
userSelectedfile: file,
|
||||
frameColor: MihColors.secondary(),
|
||||
backgroundColor: MihColors.primary(),
|
||||
onChange: () {},
|
||||
),
|
||||
FittedBox(
|
||||
child: Text(
|
||||
directoryProvider.selectedUser!.username.isNotEmpty
|
||||
|
|
|
|||
|
|
@ -206,41 +206,18 @@ class _MihPersonalQrCodeState extends State<MihPersonalQrCode> {
|
|||
backgroundColor: MihColors.secondary(),
|
||||
onChange: () {},
|
||||
)
|
||||
: FutureBuilder(
|
||||
future: futureImageUrl,
|
||||
builder: (context, asyncSnapshot) {
|
||||
if (asyncSnapshot.connectionState ==
|
||||
ConnectionState.done &&
|
||||
asyncSnapshot.hasData) {
|
||||
if (asyncSnapshot.requireData != "" ||
|
||||
asyncSnapshot.requireData.isNotEmpty) {
|
||||
return MihCircleAvatar(
|
||||
imageFile: CachedNetworkImageProvider(
|
||||
asyncSnapshot.requireData),
|
||||
width: profilePictureWidth,
|
||||
expandable: true,
|
||||
editable: false,
|
||||
fileNameController: TextEditingController(),
|
||||
userSelectedfile: file,
|
||||
frameColor: MihColors.primary(),
|
||||
backgroundColor: MihColors.secondary(),
|
||||
onChange: () {},
|
||||
);
|
||||
} else {
|
||||
return Icon(
|
||||
MihIcons.mihIDontKnow,
|
||||
size: profilePictureWidth,
|
||||
color: MihColors.primary(),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return Icon(
|
||||
MihIcons.mihRing,
|
||||
size: profilePictureWidth,
|
||||
color: MihColors.primary(),
|
||||
);
|
||||
}
|
||||
},
|
||||
: MihCircleAvatar(
|
||||
imageFile: CachedNetworkImageProvider(
|
||||
MihFileApi.getMinioFileUrlV2(user.pro_pic_path),
|
||||
),
|
||||
width: profilePictureWidth,
|
||||
expandable: true,
|
||||
editable: false,
|
||||
fileNameController: TextEditingController(),
|
||||
userSelectedfile: file,
|
||||
frameColor: MihColors.primary(),
|
||||
backgroundColor: MihColors.secondary(),
|
||||
onChange: () {},
|
||||
),
|
||||
FittedBox(
|
||||
child: Text(
|
||||
|
|
|
|||
|
|
@ -29,8 +29,15 @@ class AboutMihProvider extends ChangeNotifier {
|
|||
return success;
|
||||
}
|
||||
|
||||
Future<void> clearAboutMihCacheAndProvider() async {
|
||||
await _hiveData.clearAboutMIHCache();
|
||||
reset();
|
||||
}
|
||||
|
||||
void reset() {
|
||||
toolIndex = 0;
|
||||
userCount = null;
|
||||
businessCount = null;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ class MihMineSweeperProvider extends ChangeNotifier {
|
|||
int totalMines;
|
||||
List<MinesweeperPlayerScore>? leaderboard;
|
||||
List<MinesweeperPlayerScore>? myScoreboard;
|
||||
List<Future<String>> leaderboardUserPicturesUrl = [];
|
||||
|
||||
MihMineSweeperProvider({
|
||||
this.difficulty = "Easy",
|
||||
|
|
@ -72,10 +71,4 @@ class MihMineSweeperProvider extends ChangeNotifier {
|
|||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void setLeaderboardUserPictures(
|
||||
{required List<Future<String>> leaderboardUserPicturesUrl}) {
|
||||
this.leaderboardUserPicturesUrl = leaderboardUserPicturesUrl;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,12 +13,9 @@ class MzansiDirectoryProvider extends ChangeNotifier {
|
|||
bool personalSearch;
|
||||
List<BookmarkedBusiness> bookmarkedBusinesses = [];
|
||||
List<Business>? favouriteBusinessesList;
|
||||
Map<String, Future<String>>? favBusImagesUrl;
|
||||
List<Business> searchedBusinesses = [];
|
||||
Map<String, Future<String>>? busSearchImagesUrl;
|
||||
Business? selectedBusiness;
|
||||
List<AppUser> searchedUsers = [];
|
||||
Map<String, Future<String>>? userSearchImagesUrl;
|
||||
AppUser? selectedUser;
|
||||
String searchTerm;
|
||||
String businessTypeFilter;
|
||||
|
|
@ -88,19 +85,15 @@ class MzansiDirectoryProvider extends ChangeNotifier {
|
|||
|
||||
void setFavouriteBusinesses({
|
||||
required List<Business> businesses,
|
||||
required Map<String, Future<String>> businessesImagesUrl,
|
||||
}) {
|
||||
favouriteBusinessesList = businesses;
|
||||
favBusImagesUrl = businessesImagesUrl;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void setSearchedBusinesses({
|
||||
required List<Business> searchedBusinesses,
|
||||
required Map<String, Future<String>> businessesImagesUrl,
|
||||
}) {
|
||||
this.searchedBusinesses = searchedBusinesses;
|
||||
busSearchImagesUrl = businessesImagesUrl;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
|
|
@ -111,10 +104,8 @@ class MzansiDirectoryProvider extends ChangeNotifier {
|
|||
|
||||
void setSearchedUsers({
|
||||
required List<AppUser> searchedUsers,
|
||||
required Map<String, Future<String>> userImagesUrl,
|
||||
}) {
|
||||
this.searchedUsers = searchedUsers;
|
||||
this.userSearchImagesUrl = userImagesUrl;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ class MzansiProfileProvider extends ChangeNotifier {
|
|||
}
|
||||
|
||||
Future<bool> syncWithMihServerData() async {
|
||||
await _hiveData.processModificationsQueue();
|
||||
bool success = await _hiveData.syncProfileDataWithServer();
|
||||
loadCachedProfileState();
|
||||
return success;
|
||||
|
|
@ -84,6 +85,24 @@ class MzansiProfileProvider extends ChangeNotifier {
|
|||
refreshIndicatorKey.currentState?.show();
|
||||
}
|
||||
|
||||
bool isLocalModificationsPending(){
|
||||
return _hiveData.isModificationsNotEmpty();
|
||||
}
|
||||
|
||||
Future<bool> addUserConsent(UserConsent newConsent) async {
|
||||
bool success = await _hiveData.addUserConsentLocally(newConsent);
|
||||
await _hiveData.queuAddConsentModification(newConsent);
|
||||
await _hiveData.processModificationsQueue();
|
||||
await _hiveData.syncProfileDataWithServer();
|
||||
loadCachedProfileState();
|
||||
return success;
|
||||
}
|
||||
|
||||
Future<void> clearProfileCacheAndProvider() async {
|
||||
await _hiveData.clearProfileCache();
|
||||
reset();
|
||||
}
|
||||
|
||||
void reset() {
|
||||
personalHome = true;
|
||||
personalIndex = 0;
|
||||
|
|
@ -98,6 +117,10 @@ class MzansiProfileProvider extends ChangeNotifier {
|
|||
businessUserSignatureUrl = null;
|
||||
businessUserSignature = null;
|
||||
userConsent = null;
|
||||
employeeList = null;
|
||||
userSearchResults = [];
|
||||
personalLinks = [];
|
||||
businessLinks = [];
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -64,10 +64,16 @@ class MzansiWalletProvider extends ChangeNotifier {
|
|||
loadCachedWallet();
|
||||
}
|
||||
|
||||
Future<void> clearWalletCacheAndProvider() async {
|
||||
await _hiveData.clearWalletCache();
|
||||
reset();
|
||||
}
|
||||
|
||||
void reset() {
|
||||
toolIndex = 0;
|
||||
loyaltyCards = [];
|
||||
favouriteCards = [];
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void setToolIndex(int index) {
|
||||
|
|
|
|||
|
|
@ -4,11 +4,85 @@ import 'package:flutter/material.dart';
|
|||
import 'package:go_router/go_router.dart';
|
||||
import 'package:mih_package_toolkit/mih_package_toolkit.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_env.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_providers/mzansi_profile_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_alert_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_user_services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:supertokens_flutter/http.dart' as http;
|
||||
import 'package:supertokens_flutter/supertokens.dart';
|
||||
|
||||
class MihAuthenticationServices {
|
||||
final baseAPI = AppEnviroment.baseApiUrl;
|
||||
|
||||
bool validEmail(String email) {
|
||||
var regex = RegExp(r'^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$');
|
||||
return regex.hasMatch(email);
|
||||
}
|
||||
|
||||
Future<void> signUserUp(
|
||||
String email,
|
||||
String password,
|
||||
String confirmPassword,
|
||||
BuildContext context,
|
||||
) async {
|
||||
context.read<MzansiProfileProvider>().reset();
|
||||
if (!validEmail(email)) {
|
||||
MihAlertServices().invalidEmailAlert(context);
|
||||
} else if (password != confirmPassword) {
|
||||
MihAlertServices().passwordMatchAlert(context);
|
||||
} else {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return const Mihloadingcircle();
|
||||
},
|
||||
);
|
||||
try {
|
||||
Uri uri =
|
||||
Uri.parse("$baseAPI/auth/emailpassword/email/exists?email=$email");
|
||||
var response = await http.get(uri);
|
||||
if (response.statusCode == 200) {
|
||||
var userExists = jsonDecode(response.body);
|
||||
if (userExists["exists"]) {
|
||||
context.pop();
|
||||
MihAlertServices().emailExistsAlert(context);
|
||||
} else {
|
||||
var response2 = await http.post(
|
||||
Uri.parse("$baseAPI/auth/signup"),
|
||||
body:
|
||||
'{"formFields": [{"id": "email","value": "$email"}, {"id": "password","value": "$password"}]}',
|
||||
headers: {
|
||||
'Content-type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
},
|
||||
);
|
||||
if (response2.statusCode == 200) {
|
||||
var userCreated = jsonDecode(response2.body);
|
||||
if (userCreated["status"] == "OK") {
|
||||
String uid = await SuperTokens.getUserId();
|
||||
await MihUserServices().createUser(
|
||||
email,
|
||||
uid,
|
||||
context,
|
||||
);
|
||||
context.pop();
|
||||
} else if (userCreated["status"] == "FIELD_ERROR") {
|
||||
context.pop();
|
||||
MihAlertServices().passwordRequirementAlert(context);
|
||||
} else {
|
||||
context.pop();
|
||||
MihAlertServices().internetConnectionAlert(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} on Exception catch (error) {
|
||||
Navigator.of(context).pop();
|
||||
signUpError(error, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> signUserIn(
|
||||
String email,
|
||||
String password,
|
||||
|
|
@ -104,74 +178,28 @@ class MihAuthenticationServices {
|
|||
);
|
||||
}
|
||||
|
||||
void signUpError(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) {
|
||||
return MihPackageWindow(
|
||||
fullscreen: false,
|
||||
windowTitle: null,
|
||||
onWindowTapClose: null,
|
||||
backgroundColor: MihColors.red(),
|
||||
windowBody: Column(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.warning_amber_rounded,
|
||||
size: 100,
|
||||
color: MihColors.primary(),
|
||||
),
|
||||
Center(
|
||||
child: Text(
|
||||
"Email Already Exists",
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: MihColors.primary(),
|
||||
fontSize: 25,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
Text(
|
||||
"Here are some things to keep in mind:",
|
||||
style: TextStyle(
|
||||
color: MihColors.red(),
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
"1) Are you sure you're using the correct email address associated with your account?\n2) Is your caps lock key on? Passwords are case-sensitive.\n3) If you've forgotten your password, no worries! Click on \"Forgot Password?\" to reset it.",
|
||||
textAlign: TextAlign.left,
|
||||
style: TextStyle(
|
||||
color: MihColors.secondary(),
|
||||
fontSize: 15.0,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
MihButton(
|
||||
onPressed: () {
|
||||
context.pop();
|
||||
},
|
||||
buttonColor: MihColors.secondary(),
|
||||
width: 300,
|
||||
elevation: 10,
|
||||
child: Text(
|
||||
"Dismiss",
|
||||
style: TextStyle(
|
||||
color: MihColors.primary(),
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
void signUpError(Exception error, BuildContext context) {
|
||||
MihAlertServices().errorAdvancedAlert(
|
||||
"Sign Up Error",
|
||||
"An error occurred while signing up: $error Please try again later.",
|
||||
[
|
||||
MihButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
buttonColor: MihColors.secondary(),
|
||||
width: 200,
|
||||
child: Text(
|
||||
"Dismiss",
|
||||
style: TextStyle(
|
||||
color: MihColors.primary(),
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
context,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
import 'package:ken_logger/ken_logger.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/app_user.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/business.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_providers/mzansi_profile_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_business_details_services.dart';
|
||||
|
|
@ -12,7 +10,7 @@ class MihDataHelperServices {
|
|||
Future<void> getUserData(MzansiProfileProvider profileProvider) async {
|
||||
String url;
|
||||
await MihUserServices().getMyUserDetails(profileProvider);
|
||||
url = await MihFileApi.getMinioFileUrl(
|
||||
url = MihFileApi.getMinioFileUrlV2(
|
||||
profileProvider.user!.pro_pic_path,
|
||||
);
|
||||
profileProvider.setUserProfilePicUrl(url);
|
||||
|
|
@ -29,12 +27,12 @@ class MihDataHelperServices {
|
|||
Business? responseBusiness = await MihBusinessDetailsServices()
|
||||
.getBusinessDetailsByUser(profileProvider);
|
||||
if (responseBusiness != null) {
|
||||
logoUrl = await MihFileApi.getMinioFileUrl(
|
||||
logoUrl = MihFileApi.getMinioFileUrlV2(
|
||||
profileProvider.business!.logo_path,
|
||||
);
|
||||
profileProvider.setBusinessProfilePicUrl(logoUrl);
|
||||
await MihMyBusinessUserServices().getBusinessUser(profileProvider);
|
||||
signatureUrl = await MihFileApi.getMinioFileUrl(
|
||||
signatureUrl = MihFileApi.getMinioFileUrlV2(
|
||||
profileProvider.businessUser!.sig_path,
|
||||
);
|
||||
profileProvider.setBusinessUserSignatureUrl(signatureUrl);
|
||||
|
|
|
|||
|
|
@ -54,6 +54,23 @@ class MihUserConsentServices {
|
|||
return response.statusCode;
|
||||
}
|
||||
|
||||
Future<int?> insertUserConsentStatusV2(
|
||||
UserConsent userConsent,
|
||||
) async {
|
||||
try {
|
||||
final response = await http
|
||||
.post(
|
||||
Uri.parse("${AppEnviroment.baseApiUrl}/user-consent/insert/"),
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: jsonEncode(userConsent.toJson()),
|
||||
)
|
||||
.timeout(const Duration(seconds: 5));
|
||||
return response.statusCode;
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<int> updateUserConsentStatus(
|
||||
String latestPrivacyPolicyDate,
|
||||
String latestTermOfServiceDate,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue