Skip to content

Commit

Permalink
Set constant function fot firebase image storage
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-pratik-k committed Jul 19, 2023
1 parent 01a9b05 commit b76be36
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
4 changes: 4 additions & 0 deletions lib/data/core/utils/const/image_storage_path_const.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class ImageStoragePath{
static String spaceLogoPath({required String spaceId}) => "images/$spaceId/space-logo";
static String membersProfilePath({required String spaceId, required String uid}) => "images/$spaceId/$uid/profile";
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:injectable/injectable.dart';
import 'package:projectunity/data/core/exception/error_const.dart';
import 'package:projectunity/data/core/extensions/string_extension.dart';
import 'package:projectunity/data/core/mixin/input_validation.dart';
import 'package:projectunity/data/core/utils/const/image_storage_path_const.dart';
import 'package:projectunity/data/services/space_service.dart';
import '../../../../../data/core/utils/bloc_status.dart';
import '../../../../../data/model/space/space.dart';
Expand Down Expand Up @@ -88,8 +89,7 @@ class EditSpaceBloc extends Bloc<EditSpaceEvent, EditSpaceState>
String? logoURL = space.logo;

if (state.logo.isNotNullOrEmpty) {
final String storagePath =
'images/${_userStateNotifier.currentSpaceId}/space-logo';
final String storagePath = ImageStoragePath.spaceLogoPath(spaceId: _userStateNotifier.currentSpaceId!);
logoURL = await _storageService.uploadProfilePic(
path: storagePath, imagePath: state.logo!);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:injectable/injectable.dart';
import 'package:projectunity/data/core/extensions/date_time.dart';
import 'package:projectunity/data/core/utils/bloc_status.dart';
import 'package:projectunity/data/core/utils/const/image_storage_path_const.dart';
import 'package:projectunity/data/provider/user_state.dart';
import '../../../../../data/core/exception/error_const.dart';
import '../../../../../data/model/employee/employee.dart';
Expand Down Expand Up @@ -103,7 +104,7 @@ class AdminEditEmployeeDetailsBloc

if (state.pickedImage != null) {
imageUrl = await _storageService.uploadProfilePic(
path: 'images/${_userStateNotifier.currentSpaceId}/${event.previousEmployeeData.uid}/profile',
path: ImageStoragePath.membersProfilePath(spaceId: _userStateNotifier.currentSpaceId!, uid: event.previousEmployeeData.uid),
imagePath: state.pickedImage!);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:injectable/injectable.dart';
import 'package:projectunity/data/core/mixin/input_validation.dart';
import 'package:projectunity/data/core/utils/const/image_storage_path_const.dart';
import '../../../../../data/core/exception/error_const.dart';
import '../../../../../data/core/utils/bloc_status.dart';
import '../../../../../data/model/employee/employee.dart';
Expand Down Expand Up @@ -97,7 +98,7 @@ class EmployeeEditProfileBloc
}

Future<String?> _saveImage() async {
final String storagePath = 'images/${_userManager.currentSpaceId}/${_userManager.userUID}/profile';
final String storagePath = ImageStoragePath.membersProfilePath(spaceId: _userManager.currentSpaceId!, uid: _userManager.userUID!);

if (state.imageURL != null) {
try {
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/space/create_space/bloc/create_workspace_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:image_picker/image_picker.dart';
import 'package:injectable/injectable.dart';
import 'package:projectunity/data/core/exception/error_const.dart';
import 'package:projectunity/data/core/mixin/input_validation.dart';
import 'package:projectunity/data/core/utils/const/image_storage_path_const.dart';
import 'package:projectunity/data/model/employee/employee.dart';
import 'package:projectunity/data/model/space/space.dart';
import 'package:projectunity/data/services/employee_service.dart';
Expand Down Expand Up @@ -140,8 +141,7 @@ class CreateSpaceBLoc extends Bloc<CreateSpaceEvent, CreateSpaceState>
int timeOff = int.parse(state.paidTimeOff);

if (state.logo != null) {
final String storagePath =
'images/$newSpaceId/space-logo';
final String storagePath = ImageStoragePath.spaceLogoPath(spaceId: newSpaceId);
logoURL = await storageService.uploadProfilePic(
path: storagePath, imagePath: state.logo!);
}
Expand Down

0 comments on commit b76be36

Please sign in to comment.