nui_media 0.0.45
nui_media: ^0.0.45 copied to clipboard
Flutter package for media actions such as selecting image/video from gallery or taking new photo/video.
id: flutter-sdk-nuimedia title: NUIMedia Overview sidebar_label: Overview #
NUIMedia is part of the Flutter SDK that allows you to perform media selection, taking photos/videos with compression for a simpler media integration.
Builder Method for NUIMedia #
| Method | Remark |
|---|---|
module() |
Specify the module for this NUIMedia instance |
build() |
Build the NUIMedia instance with the builder. |
Initialize NUIMedia with NUIMediaBuilder. #
Create a NUIMediaBuilder instance to build the NUIMedia instance.
var builder = NUIMediaBuilder();
Specifying the module for NUIMedia. #
On the builder method, users specify the module of the NUIMedia instance.
builder.module("app");
Build the NUIMedia instance #
Once all the configurations are done for the NUIMediaBuilder, building the instance will return the instance of the NUIMedia.
NUIMedia media = builder.build();
A Complete Example for Building A NUIDatabase Instance #
final db = NUIMediaBuilder()
.module("app")
.build();
Available Methods for NUIMedia #
| Method | Remark |
|---|---|
get() |
Get the instance of the built NUIMedia instance |
takePhoto() |
Take a photo with the camera |
recordVideo() |
Record a video with the camera |
getFromGallery() |
Get list of photos/videos from the gallery |
compressImage() |
Compress an image |
compressVideo() |
Compress a video |
compressVideoWithBitmap() |
Compress a video with the thumb bitmap |
getImageInfo() |
Get information for an image |
getVideoInfo() |
Get information for a video |
showFileSelection() |
Show the selector for photos or videos from the gallery |
Getting the NUIMedia Instance #
Users can get the NUIMedia instance built previously with NUIMediaBuilder.
final media = NUIMedia.get();
Take a Photo #
- Parameters:
Name Type Nullable Remark contextBuildContextN The context of the current widget maxWidthdoubleY The maximum width of the image maxHeightdoubleY The maximum height of the image imageQualityintY The image quality selfieboolY True for selfie mode and false for rear camera
Example of Taking a Photo #
final imageFile = await NUIMedia.get().takePhoto(context);
Record a Video #
- Parameters:
Name Type Nullable Remark contextBuildContextN The context of the current widget maxWidthdoubleY The maximum width of the video maxHeightdoubleY The maximum height of the video imageQualityintY The video quality selfieboolY True for selfie mode and false for rear camera
Example of Recording a Video #
final videoFile = await NUIMedia.get().recordVideo(context);
Get from Gallery #
- Parameters:
Name Type Nullable Remark optionNUIMediaGalleryOptionY To get only photos, videos or both limitintY Limit the number of files returned, default to 100
Example of Getting from Gallery #
final files = await NUIMedia.get().getFromGallery(option: NUIMediaGalleryOption.BOTH);
Compress an Image #
- Parameters:
Name Type Nullable Remark fileFileN The file to be compressed targetPathStringY The target path of the compressed file maxWidthdoubleY Maximum width of the compressed file maxHeightdoubleY Maximum height of the compressed file qualityintY Quality of the compressed image from 1 to 100
Example of Compressing an Image #
final compressedFile = NUIMedia.get().compressImage(file, maxWidth: 720, maxHeight: 720, quality: 95);
Compress a Video #
- Parameters:
Name Type Nullable Remark fileFileN The file to be compressed targetPathStringY The target path of the compressed file qualityVideoQualityY Quality of the compressed video, Low, Medium or High deleteOriginboolY Delete the origin file after successful compression includeAudioboolY Include or exclude the audio of the video
Example of Compressing a Video #
final compressedFile = NUIMedia.get().compressVideo(file, quality: VideoQuality.MediumQuality);
Compress a Video with Bitmap #
- Parameters:
Name Type Nullable Remark fileFileN The file to be compressed targetPathStringY The target path of the compressed file qualityVideoQualityY Quality of the compressed video, Low, Medium or High deleteOriginboolY Delete the origin file after successful compression includeAudioboolY Include or exclude the audio of the video maxHeightdoubleY Maximum height of the compressed image bitmap maxWidthdoubleY Maximum width of the compressed image bitmap
Example of Compressing a Video with Bitmap #
final compressedFile = NUIMedia.get().compressVideo(file, quality: VideoQuality.MediumQuality, maxWidth: 720, maxHeight: 720);
Compress Media Files #
- Parameters:
Name Type Nullable Remark filesList<NUIMediaFile>N List of NUIMediaFile(s) to be compressed
Example of Compressing Media Files #
final compressedFiles = await NUIMedia.get().compressMediaFiles(files: [file1, file2]);
Show File Selection #
- Parameters:
Name Type Nullable Remark contextBuildContextN The context of the current widget selectionsList<NUIMediaFileY The selections chosen previously to be filled in enableCropboolY Enable the cropping feature to crop the image directly minimumSelectionintY Minimum files to be selected maximumSelectionintY Maximum files selectable typeNUIMediaGalleryOptionY Indicate photo or video selections or both accentColorColorY The accent color for the picker'style accentColorBrightColorY The accent gradient color for the picker's style
Example of Showing the Files Selection #
final selectedFiles = await NUIMedia.get().showFileSelection(context, enableCrop: true, cropRatio: 1.0, minimumSelection: 5);