搜尋套件、儲存庫與 APP 分類

widget_mask 封面
套件詳情v1.0.0+0

widget_mask

使用一個組件來遮罩並混合另一個組件,例如將文字印在表面上。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
10
喜歡數
70
Pub 分數
150

安裝套件

flutter pub add widget_mask

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

widget_mask 套件讓開發者能使用一個 widget 作為遮罩來裁切或混合另一個 widget,進而實現將文字印在表面等創意視覺效果。它利用 Flutter 的組合能力應用 alpha 遮罩,非常適合具備透明度與圖層的進階 UI 設計。該套件輕量且可無縫整合至現有的跨平台 Flutter 專案中。支援靜態與動態遮罩情境,提升自訂 widget 組合的彈性。

適用情境

  • 在圖像上創建文字疊加
  • 設計分層的使用者介面元素
  • 實現自定義裁剪路徑
  • 構建動畫遮罩過渡
  • 使用透明度製作視覺效果
  • 透過遮罩圖形增強應用品牌識別

主要特色

  • 支援任何小工具作為遮罩
  • 高效渲染,開銷最小
  • 跨平台相容性
  • 靈活的混合模式
  • 透過簡單 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 項

原始碼儲存庫

使用此套件的專案