masamune_picker 3.2.6 copy "masamune_picker: ^3.2.6" to clipboard
masamune_picker: ^3.2.6 copied to clipboard

Package for retrieving files such as images and videos from terminal storage, cameras, etc.

Masamune logo

Masamune Picker

Follow on GitHub Follow on X Follow on YouTube Maintained with Melos

GitHub Sponsor


[GitHub] | [YouTube] | [Packages] | [X] | [LinkedIn] | [mathru.net]


Masamune Picker #

Usage #

Installation #

Add the package to your project.

flutter pub add masamune_picker

Run flutter pub get when editing pubspec.yaml manually.

Register the Adapter #

PickerMasamuneAdapter integrates file selection, camera capture, and storage handling. Register it before runApp.

// lib/adapter.dart

/// Masamune adapters used in the application.
final masamuneAdapters = <MasamuneAdapter>[
  const UniversalMasamuneAdapter(),

  const PickerMasamuneAdapter(),
];

The adapter provides platform-specific implementations for mobile, desktop, and web, exporting storage utilities under storage/.

Basic Usage #

Use the Picker controller to select files or capture from camera.

Pick a Single Image:

class MyPage extends PageScopedWidget {
  @override
  Widget build(BuildContext context, PageRef ref) {
    final picker = ref.page.controller(Picker.query());

    return ElevatedButton(
      onPressed: () async {
        final image = await picker.pickSingle(
          type: PickerFileType.image,
          dialogTitle: "Select an image",
        );
        
        if (image != null) {
          print("Selected: ${image.path}");
          print("Size: ${image.bytes?.length} bytes");
        }
      },
      child: const Text("Pick Image"),
    );
  }
}

Pick Multiple Files:

final files = await picker.pickMultiple(
  type: PickerFileType.custom(["pdf", "docx", "txt"]),
  dialogTitle: "Select documents",
);

for (final file in files) {
  print("File: ${file.name}, Size: ${file.bytes?.length}");
}

Access Last Selection:

// Access the last selected files
final lastFiles = picker.value;
if (lastFiles != null && lastFiles.isNotEmpty) {
  print("Last picked: ${lastFiles.first.name}");
}

// Listen for changes
picker.addListener(() {
  final files = picker.value;
  // Update UI with selected files
});

Camera Capture #

On supported platforms, capture photos or videos directly from the camera:

// Capture a photo
final photo = await picker.pickCamera(
  type: PickerFileType.image,
  dialogTitle: "Take a photo",
);

// Capture a video
final video = await picker.pickCamera(
  type: PickerFileType.video,
  dialogTitle: "Record a video",
);

Error Handling:

try {
  final photo = await picker.pickCamera(type: PickerFileType.image);
  print("Captured: ${photo?.path}");
} on MasamunePickerPermissionDeniedException {
  print("Camera permission denied");
  // Show permission request dialog
} catch (e) {
  print("Picker error: $e");
}

File Types #

Specify the type of files to allow:

// Any file
await picker.pickSingle(type: PickerFileType.any);

// Images only
await picker.pickSingle(type: PickerFileType.image);

// Videos only
await picker.pickSingle(type: PickerFileType.video);

// Audio files
await picker.pickSingle(type: PickerFileType.audio);

// Custom extensions
await picker.pickSingle(
  type: PickerFileType.custom(["pdf", "docx", "xlsx"]),
);

Display Selected Images #

Show selected images in your UI:

class ImagePickerWidget extends PageScopedWidget {
  @override
  Widget build(BuildContext context, PageRef ref) {
    final picker = ref.page.controller(Picker.query());

    return Column(
      children: [
        // Display selected images
        if (picker.value != null && picker.value!.isNotEmpty)
          Wrap(
            spacing: 8,
            children: picker.value!.map((file) {
              return Image.memory(
                file.bytes!,
                width: 100,
                height: 100,
                fit: BoxFit.cover,
              );
            }).toList(),
          ),
        
        // Pick button
        ElevatedButton(
          onPressed: () async {
            await picker.pickMultiple(type: PickerFileType.image);
          },
          child: const Text("Select Images"),
        ),
      ],
    );
  }
}

Tips #

  • Use PickerFileType.custom() for specific file extensions
  • Provide localized dialog titles via the dialogTitle parameter
  • Monitor picker.future to show loading indicators during selection
  • Combine with masamune_camera for advanced capture scenarios
  • Use with storage adapters to automatically upload selected files to cloud storage

GitHub Sponsors #

Sponsors are always welcome. Thank you for your support!

https://github.com/sponsors/mathrunet

0
likes
150
points
3.73k
downloads

Documentation

API reference

Publisher

verified publishermathru.net

Weekly Downloads

Package for retrieving files such as images and videos from terminal storage, cameras, etc.

Homepage
Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

file_picker, flutter, image, image_picker, katana, masamune, mime

More

Packages that depend on masamune_picker