image_uploader
is a modular and extensible Dart package that simplifies file upload and deletion processes using either Firebase Storage or a REST API-based service. Built with dependency injection and clean architecture principles, this package is designed to integrate easily into your Flutter backend logic.
- Upload files to Firebase Storage or a REST API.
- Delete files from Firebase Storage or REST API.
- Encapsulated
FileEntity
andFileResponseEntity
models. - Clean separation of concerns via repositories and services.
- Plug-and-play registration using
get_it
.
Add the following to your pubspec.yaml
:
dependencies:
image_uploader: <latest_version>
Then run:
flutter pub get
Choose your data source by passing ImageUploaderSource
enum to the fileRegisterGetItDi()
function:
fileRegisterGetItDi(ImageUploaderSource.firebase);
fileRegisterGetItDi(ImageUploaderSource.restApi);
final uploadFile = sl<UploadFile>();
final deleteFile = sl<DeleteFile>();
final fileEntity = FileEntity(
file: file,
fileName: 'example.jpg',
fileType: 'image',
path: 'user_uploads',
);
final result = await uploadFile(fileEntity);
class FileEntity {
final File? file;
final Uint8List? bytes;
final String? path;
final String? fileName;
final String? fileType;
final String? uploadingToastTxt;
}
class FileResponseEntity {
final String? fileName;
final String? imgUrl;
}
abstract class IFileRepository {
Future<Either<IFailure, String>> uploadFile(FileEntity fileEntity);
Future<Either<IFailure, bool>> deleteFile(String imgUrl);
}
Implement your own IFileRepository
, IFireStorageService
, or IImageServiceRestApiDataSource
to customize how uploading/deleting is handled.
- Firebase setup (if using Firebase Storage)
dartz
,exception_type
,i_tdd
for result handling and abstractions
MIT License. See LICENSE
file for details.
Developed and Maintained with ❤️ by Shohidul Islam. Contributions welcome!