You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
124 lines
4.2 KiB
Dart
124 lines
4.2 KiB
Dart
import 'dart:io';
|
|
import 'package:car_provider_app/config/provider_routes.dart';
|
|
import 'package:car_provider_app/views/settings/branch/dealer/widget/add_phone_num_wiget.dart';
|
|
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
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_models/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/enums.dart';
|
|
import 'package:mc_common_app/utils/location/Location.dart';
|
|
import 'package:mc_common_app/utils/navigator.dart';
|
|
import 'package:mc_common_app/utils/shared_prefrence.dart';
|
|
import 'package:mc_common_app/utils/utils.dart';
|
|
import 'package:mc_common_app/view_models/base_view_model.dart';
|
|
import 'package:mc_common_app/widgets/bottom_sheet.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 > 1000000) {
|
|
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<ImageResponse> updateUserImage(String image) async {
|
|
return await userRepo.updateUserImage(image);
|
|
}
|
|
|
|
fetchUsernameAndLocation() async {
|
|
String userName = await SharedPrefManager.getPhoneOrEmail();
|
|
Location.getCurrentLocation(
|
|
(LatLng? latlng) {
|
|
AppState().currentLocation = latlng ?? const LatLng(0, 0);
|
|
},
|
|
);
|
|
notifyListeners();
|
|
}
|
|
|
|
updateIndex(int i) {
|
|
selectedNavbarBarIndex = i;
|
|
notifyListeners();
|
|
}
|
|
|
|
void checkUserSubscription(SubscriptionActionTypeEnum actionType, BuildContext context, {required Function() callback}) async {
|
|
switch (actionType) {
|
|
case SubscriptionActionTypeEnum.ads:
|
|
performCheckOnAds(context);
|
|
break;
|
|
case SubscriptionActionTypeEnum.users:
|
|
performCheckOnUsers(context, callback);
|
|
break;
|
|
case SubscriptionActionTypeEnum.branches:
|
|
performCheckOnBranches(context);
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
void performCheckOnBranches(BuildContext context) async {
|
|
if (AppState().getproviderSubscription.isNotEmpty && AppState().getproviderSubscription.first.branchesRemaining! > 0) {
|
|
await navigateWithName(context, ProviderAppRoutes.defineBranch);
|
|
} else {
|
|
Utils.showToast("Upgrade your subscription to add more Branches.");
|
|
}
|
|
}
|
|
|
|
void performCheckOnAds(BuildContext context) async {
|
|
if (AppState().getproviderSubscription.isNotEmpty && AppState().getproviderSubscription.first.adsRemaining! > 0) {
|
|
await navigateWithName(context, ProviderAppRoutes.defineBranch);
|
|
} else {
|
|
Utils.showToast("Upgrade your subscription to add more Ads.");
|
|
}
|
|
}
|
|
|
|
void performCheckOnUsers(BuildContext context, Function() callBack) async {
|
|
if (AppState().getproviderSubscription.isNotEmpty && AppState().getproviderSubscription.first.subUsersRemaining! > 0) {
|
|
showMyBottomSheet(
|
|
context,
|
|
isDismissible: false,
|
|
child: const AddPhoneNumWidget(),
|
|
callBackFunc: callBack
|
|
);
|
|
} else {
|
|
Utils.showToast("Upgrade your subscription to add more Sub Users.");
|
|
}
|
|
}
|
|
}
|