A highly customizable, cross-platform image picking, cropping, and compression toolkit built on top of Flutter's image_picker
, image_cropper
, and flutter_image_compress
. This adapter provides a modular, testable, and UI-agnostic solution for seamless image selection and preprocessing in your apps.
- ✅ Platform-aware image selection from camera or gallery
- ✂️ Optional image cropping (with customizable UI)
- 🗜️ Optional image compression
- 🧩 Modular architecture (SOLID principles)
- 🔄 Supports Cubit for state-driven image picking
- 🖼️ Custom UI builders for both avatar and image pickers
- 📦 Easy to plug into any Flutter app via DI and
BlocProvider
Add the following to your pubspec.yaml
:
dependencies:
image_picker_adapter: latest_version
Then run:
flutter pub get
┌──────────────────────────┐
│ AppImagePicker │ ◄── Customizable Widget
├──────────────────────────┤
│ ↳ ImagePickerCubit │ ◄── Handles image picking states
│ ↳ ImagePickerManager │ ◄── Coordinates services
│ ↳ AppImagePickerService
│ ↳ IImageCropperService
│ ↳ IImageCompressorService
└──────────────────────────┘
void registerImagePickerAdapterDependencies() {
sl.registerLazySingleton<AppImagePickerService>(() => AppImagePickerService());
sl.registerLazySingleton<IImageCropperService>(() => AppImageCropperService());
sl.registerLazySingleton<IImageCompressorService>(() => AppImageCompressorService());
sl.registerLazySingleton<ImagePickerManager>(
() => ImagePickerManager(
pickerService: sl<AppImagePickerService>(),
cropperService: sl<IImageCropperService>(),
compressorService: sl<IImageCompressorService>(),
),
);
sl.registerFactory(
() => ImagePickerCubit(imagePickerManager: sl<ImagePickerManager>()),
);
}
List<SingleChildWidget> imagePickerAdapterBlocProviders = [
BlocProvider<ImagePickerCubit>(create: (_) => sl<ImagePickerCubit>()),
];
AppImagePicker(
imageQuality: 80,
crop: true,
compress: true,
onChanged: (file) {
// Do something with XFile
},
builder: (file) => CircleAvatar(
backgroundImage: file != null ? FileImage(File(file.path)) : null,
),
)
AvatarImagePicker(
imageSource: user.avatarUrl,
radius: 40,
crop: true,
compress: true,
onChanged: (file) => print('Picked: ${file?.path}'),
)
extension XFileParserExtension on XFile {
Future<T?> parseAs<T>() async {
if (T == File) return File(path) as T;
if (T == Uint8List) return await readAsBytes() as T;
if (T == String) return path as T;
if (T == XFile) return this as T;
throw UnsupportedError('Unsupported type conversion: $T');
}
}
bottomSheet
(default)alertDialog
custom
You can inject your own selector widget or use built-in ones like SourceSelectorDialog
or ImageSourceSelector
.
- Build your own image viewer UI with
builder
inAppImagePicker
- Customize source selection UI via
IImageSourceSelectorService
- Provide your own crop/compress service by implementing
IImageCropperService
,IImageCompressorService
MIT License
Feel free to open issues, pull requests or contribute ideas to enhance the image_picker_adapter
.
- image_picker
- image_cropper
- flutter_image_compress
- Inspired by real-world production usage in Flutter apps
image_picker_adapter Developed with ❤️ by Shohidul Islam