nui_media 0.0.7 copy "nui_media: ^0.0.7" to clipboard
nui_media: ^0.0.7 copied to clipboard

outdated

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
    context BuildContext N The context of the current widget
    maxWidth double Y The maximum width of the image
    maxHeight double Y The maximum height of the image
    imageQuality int Y The image quality
    selfie bool Y 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
    context BuildContext N The context of the current widget
    maxWidth double Y The maximum width of the video
    maxHeight double Y The maximum height of the video
    imageQuality int Y The video quality
    selfie bool Y True for selfie mode and false for rear camera

Example of Recording a Video #

final videoFile = await NUIMedia.get().recordVideo(context);
  • Parameters:
    Name Type Nullable Remark
    option NUIMediaGalleryOption Y To get only photos, videos or both
    limit int Y Limit the number of files returned, default to 100
final files = await NUIMedia.get().getFromGallery(option: NUIMediaGalleryOption.BOTH);

Compress an Image #

  • Parameters:
    Name Type Nullable Remark
    file File N The file to be compressed
    targetPath String Y The target path of the compressed file
    maxWidth double Y Maximum width of the compressed file
    maxHeight double Y Maximum height of the compressed file
    quality int Y 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
    file File N The file to be compressed
    targetPath String Y The target path of the compressed file
    quality VideoQuality Y Quality of the compressed video, Low, Medium or High
    deleteOrigin bool Y Delete the origin file after successful compression
    includeAudio bool Y 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
    file File N The file to be compressed
    targetPath String Y The target path of the compressed file
    quality VideoQuality Y Quality of the compressed video, Low, Medium or High
    deleteOrigin bool Y Delete the origin file after successful compression
    includeAudio bool Y Include or exclude the audio of the video
    maxHeight double Y Maximum height of the compressed image bitmap
    maxWidth double Y 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
    files List<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
    context BuildContext N The context of the current widget
    selections List<NUIMediaFile Y The selections chosen previously to be filled in
    enableCrop bool Y Enable the cropping feature to crop the image directly
    minimumSelection int Y Minimum files to be selected
    maximumSelection int Y Maximum files selectable
    type NUIMediaGalleryOption Y Indicate photo or video selections or both
    accentColor Color Y The accent color for the picker'style
    accentColorBright Color Y 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);