image_picker_adapter 0.0.6
image_picker_adapter: ^0.0.6 copied to clipboard
A modular and customizable image picker adapter for Flutter. Supports image cropping, compression, source selection, and Cubit-based state management. Built with SOLID principles and clean architecture.
๐ฆ image_picker_adapter #
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.
๐ Features #
- โ 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
๐ฆ Installation #
Add the following to your pubspec.yaml:
dependencies:
image_picker_adapter: latest_version
Then run:
flutter pub get
๐งฑ Architecture Overview #
โโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ AppImagePicker โ โโโ Customizable Widget
โโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โณ ImagePickerCubit โ โโโ Handles image picking states
โ โณ ImagePickerManager โ โโโ Coordinates services
โ โณ AppImagePickerService
โ โณ IImageCropperService
โ โณ IImageCompressorService
โโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ ๏ธ Getting Started #
1. โ Register Dependencies #
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>()),
);
}
2. ๐ง Provide Bloc #
List<SingleChildWidget> imagePickerAdapterBlocProviders = [
BlocProvider<ImagePickerCubit>(create: (_) => sl<ImagePickerCubit>()),
];
3. ๐จ Use AppImagePicker Widget #
AppImagePicker(
imageQuality: 80,
crop: true,
compress: true,
onChanged: (file) {
// Do something with XFile
},
builder: (file) => CircleAvatar(
backgroundImage: file != null ? FileImage(File(file.path)) : null,
),
)
๐ค Avatar Picker Example #
AvatarImagePicker(
imageSource: user.avatarUrl,
radius: 40,
crop: true,
compress: true,
onChanged: (file) => print('Picked: ${file?.path}'),
)
๐งช Extension Utilities #
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');
}
}
๐งญ Source Selector Modes #
bottomSheet(default)alertDialogcustom
You can inject your own selector widget or use built-in ones like SourceSelectorDialog or ImageSourceSelector.
๐งฉ Customization #
- Build your own image viewer UI with
builderinAppImagePicker - Customize source selection UI via
IImageSourceSelectorService - Provide your own crop/compress service by implementing
IImageCropperService,IImageCompressorService
๐ License #
MIT License
๐ Contributions #
Feel free to open issues, pull requests or contribute ideas to enhance the image_picker_adapter.
๐ง Credits #
- image_picker
- image_cropper
- flutter_image_compress
- Inspired by real-world production usage in Flutter apps
๐จโ๐ผ Author #
image_picker_adapter Developed with โค๏ธ by Shohidul Islam