パッケージ、リポジトリ、アプリカテゴリを検索

widget_mask のカバー
パッケージ詳細v1.0.0+0

widget_mask

別のウィジェットをマスクしてブレンドするためのウィジェットを使用します。たとえば、テキストを表面にインプリントする場合などです。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
10
いいね数
70
Pub ポイント
150

パッケージをインストール

flutter pub add widget_mask

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

widget_mask パッケージは、開発者が1つのウィジェットをマスクとして使って、別のウィジェットを切り取ったりブレンドしたりできるようにし、表面にテキストをインプリントするなどの創造的なビジュアル効果を実現します。Flutterのコンポジション機能を活用してアルファマスクを適用することで、透明度やレイヤー処理を伴う高度なUIデザインに最適です。このパッケージは軽量で、複数プラットフォームに対応する既存のFlutterプロジェクトにスムーズに統合可能です。静的および動的マスキングの両方をサポートしており、カスタムウィジェットの組み合わせにおける柔軟性を高めます。

用途

  • 画像にテキストオーバーレイを作成する
  • レイヤードUI要素の設計
  • カスタムクリッピングパスの実装
  • アニメーションマスク遷移の構築
  • 透過性を用いたビジュアルエフェクトの生成
  • マスクされたグラフィックによるアプリのブランディング強化

主な機能

  • 任意のウィジェットをマスクとしてサポート
  • 最小限のオーバーヘッドで効率的なレンダリング
  • クロスプラットフォーム互換性
  • 柔軟なブレンドモード
  • 簡単なAPIによるスムーズな統合
  • ダイナミックマスクの更新

適している対象

  • 高度なビジュアルエフェクトを求めるUIデザイナー
  • ブランドまたはアート的なインターフェースを構築する開発者
  • テキストオンサーフェス効果を必要とするアプリ
  • 複雑なレイヤーと透過性を使用するプロジェクト
  • クリエイティブなコンポジションを探るFlutter開発者

注意事項

  • 重いマスクを使用するとパフォーマンスに影響する可能性があります
  • Flutter のペイントシステムの理解が必要です
  • マスクとしてレンダリングできるウィジェットに制限
  • 最適化なしでは、高周波アニメーションには適していません
  • 予測可能で安定したマスク形状と併用するのが最適です

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

pub.dev package page GitHub Actions CI GitHub Stars

Use a widget to mask and blend another widget, for example to imprint text onto surfaces.


If you're looking for a database solution, check out cbl, another project of mine. It brings Couchbase Lite to standalone Dart and Flutter, with support for:

  • Full-Text Search,
  • Expressive Queries,
  • Data Sync,
  • Change Notifications

and more.


Limitations

Widgets that are used as children of WidgetMask or SaveLayer must not need compositing, or contain widgets which need compositing, such as RepaintBoundary.

This is because this package makes use of save layers, which cannot encompass compositing layers.

Masks and blending

A mask is an image, which is positioned in front of another image and affects this images in some way, where it is not empty.

Blending is a process which takes two images and produces a new image by applying a mathematical function to each pair of pixels from the input images. For some of these functions, the order of the arguments matters. That's why the input images are labeled with src and dst. A mask is usually the image labeled with src.

Getting started

The example below paints some text onto an image. The text is filled with the negative of the image.

WidgetMask(
  // `BlendMode.difference` results in the negative of `dst` where `src`
  // is fully white. That is why the text is white.
  blendMode: BlendMode.difference,
  mask: Center(
    child: Text(
      'Negative',
      style: TextStyle(
        fontSize: 50,
        color: Colors.white,
      ),
    ),
  ),
  child: Image.asset('images/my_image.jpg'),
);

WidgetMask delegates to child to lay itself out. It always has the same size as child. mask is forced to adopt the same size as child and positioned on top it.

During hit testing mask is positioned over child.

The different BlendModes use src and dst to describe how the colors of two images are blended with each other. In the context of WidgetMask mask is the src and child the dst.

Examples

The NegativeMaskedImageDemo widget, in the example app, implements the image at the top.

SaveLayer

This widget paints its child into a save layer and allows you to fully specify the Paint to use with the save layer. If you need to use a custom Paint or require a different layout of the widgets, you can use SaveLayer.

WidgetMask is implement using two SaveLayers to blend the mask and child:

@override
Widget build(BuildContext context) {
  Widget child = Stack(
    textDirection: TextDirection.ltr,
    fit: StackFit.passthrough,
    children: [
      this.child,
      Positioned.fill(
        child: SaveLayer(
          paint: Paint()..blendMode = blendMode,
          child: mask,
        ),
      ),
    ],
  );

  if (childSaveLayer) {
    child = SaveLayer(
      child: child,
    );
  }

  return child;
}

Gabriel Terwesten • GitHub @blaugold • Twitter @GTerwesten • Medium @gabriel.terwesten

カテゴリー

依存関係

依存関係一覧 1 件

ソースリポジトリ

このパッケージを使用しているプロジェクト