import 'dart:io'; import 'package:mc_common_app/classes/app_state.dart'; import 'package:mc_common_app/generated/locale_keys.g.dart'; import 'package:mc_common_app/models/user/image_response.dart'; import 'package:mc_common_app/repositories/user_repo.dart'; import 'package:mc_common_app/services/common_services.dart'; import 'package:mc_common_app/utils/utils.dart'; import 'package:mc_common_app/view_models/base_view_model.dart'; import 'package:flutter/cupertino.dart'; import 'package:easy_localization/easy_localization.dart'; class DashboardVM extends BaseVM { final CommonAppServices commonServices; final UserRepo userRepo; DashboardVM({required this.commonServices, required this.userRepo}); String pickedImage = ""; int selectedNavbarBarIndex = 2; void onNavbarTapped(int index) { selectedNavbarBarIndex = index; notifyListeners(); } void pickImageFromPhone(BuildContext context, int sourceFlag) async { final File? pickedImageFile = await commonServices.pickImageFromPhone(sourceFlag); if (pickedImageFile == null) { return; } int sizeInBytes = pickedImageFile.lengthSync(); if (sizeInBytes > 1000) { Utils.showToast(LocaleKeys.fileLarger.tr()); return; } else { String image64 = Utils.convertFileToBase64(pickedImageFile); Utils.showLoading(context); ImageResponse response = await userRepo.updateUserImage(image64); Utils.hideLoading(context); Navigator.pop(context); if (response.messageStatus == 1) { Utils.showToast(LocaleKeys.imageUploaded.tr()); AppState().getUser.data!.userInfo!.userImageUrl = response.data; } else { Utils.showToast(response.message ?? ""); } } } Future updateUserImage(String image) async { return await userRepo.updateUserImage(image); } }