Class FlutterImageView

java.lang.Object
android.view.View
io.flutter.embedding.android.FlutterImageView
All Implemented Interfaces:
Drawable.Callback, AccessibilityEventSource, KeyEvent.Callback, RenderSurface
Direct Known Subclasses:
PlatformOverlayView

public class FlutterImageView extends View implements RenderSurface
Paints a Flutter UI provided by an ImageReader onto a Canvas.

A FlutterImageView is intended for situations where a developer needs to render a Flutter UI, but also needs to render an interactive PlatformView.

This View takes an ImageReader that provides the Flutter UI in an Image and renders it to the Canvas in onDraw.

  • Constructor Details

    • FlutterImageView

      public FlutterImageView(@NonNull Context context, int width, int height, FlutterImageView.SurfaceKind kind)
      Constructs a FlutterImageView with an ImageReader that provides the Flutter UI.
    • FlutterImageView

      public FlutterImageView(@NonNull Context context)
    • FlutterImageView

      public FlutterImageView(@NonNull Context context, @NonNull AttributeSet attrs)
  • Method Details

    • getImageReader

      public ImageReader getImageReader()
    • getSurface

      @NonNull public Surface getSurface()
    • getAttachedRenderer

      @Nullable public FlutterRenderer getAttachedRenderer()
      Description copied from interface: RenderSurface
      Returns the FlutterRenderer that is attached to this RenderSurface, or null if no FlutterRenderer is currently attached.
      Specified by:
      getAttachedRenderer in interface RenderSurface
    • attachToRenderer

      public void attachToRenderer(@NonNull FlutterRenderer flutterRenderer)
      Invoked by the owner of this FlutterImageView when it wants to begin rendering a Flutter UI to this FlutterImageView.
      Specified by:
      attachToRenderer in interface RenderSurface
    • detachFromRenderer

      public void detachFromRenderer()
      Invoked by the owner of this FlutterImageView when it no longer wants to render a Flutter UI to this FlutterImageView.
      Specified by:
      detachFromRenderer in interface RenderSurface
    • pause

      public void pause()
      Description copied from interface: RenderSurface
      Instructs this RenderSurface to stop forwarding Surface notifications to the FlutterRenderer that was previously connected with RenderSurface.attachToRenderer(FlutterRenderer).
      Specified by:
      pause in interface RenderSurface
    • resume

      public void resume()
      Description copied from interface: RenderSurface
      Instructs this RenderSurface to resume forwarding Surface notifications to the FlutterRenderer that was previously connected with RenderSurface.attachToRenderer(FlutterRenderer).
      Specified by:
      resume in interface RenderSurface
    • acquireLatestImage

      public boolean acquireLatestImage()
      Acquires the next image to be drawn to the Canvas. Returns true if there's an image available in the queue.
    • resizeIfNeeded

      public void resizeIfNeeded(int width, int height)
      Creates a new image reader with the provided size.
    • closeImageReader

      public void closeImageReader()
      Closes the image reader associated with the current FlutterImageView.

      Once the image reader is closed, calling acquireLatestImage will result in an IllegalStateException.

    • onDraw

      protected void onDraw(Canvas canvas)
      Overrides:
      onDraw in class View
    • onSizeChanged

      protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight)
      Overrides:
      onSizeChanged in class View