๐Ÿ“ฆ 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)
  • alertDialog
  • custom

You can inject your own selector widget or use built-in ones like SourceSelectorDialog or ImageSourceSelector.


๐Ÿงฉ Customization

  • Build your own image viewer UI with builder in AppImagePicker
  • 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


๐Ÿ‘จโ€๐Ÿ’ผ Author

image_picker_adapter Developed with โค๏ธ by Shohidul Islam