欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Flutter將整個App變?yōu)榛疑暮唵螌崿F(xiàn)方法

 更新時間:2021年12月14日 09:03:02   作者:堅果前端の博客  
Flutter?是?Google?開源的?UI?工具包,幫助開發(fā)者通過一套代碼庫高效構(gòu)建多平臺精美應(yīng)用,這篇文章主要給大家介紹了關(guān)于Flutter將整個App變?yōu)榛疑膶崿F(xiàn)方法,在Flutter中實現(xiàn)整個App變?yōu)榛疑欠浅:唵蔚?需要的朋友可以參考下

前言

為了讓更多的人永遠記住12月13日,各大廠都在這一天將應(yīng)用變灰了。

image-20211213081824100

那么接下來我們看一下Flutter是如何實現(xiàn)的。

Flutter中實現(xiàn)整個App變?yōu)榛疑?/h2>

在Flutter中實現(xiàn)整個App變?yōu)榛疑欠浅:唵蔚模?/p>

只需要在最外層的控件上包裹ColorFiltered,用法如下:

ColorFiltered(顏色過濾器)

看名字就知道是增加顏色濾鏡效果的,

ColorFiltered(
      colorFilter:ColorFilter.mode(Colors.grey, BlendMode.color),
      child: child,
    );

將上面代碼放到全局根widget下,即可設(shè)置全部頁面顏色變灰

通過colorFilter可設(shè)置某種顏色過濾,比如變灰設(shè)置灰色即可,以及顏色混合模式
ColorFiltered 小部件繼承SingleChildRenderObjectWidget,因此會提供一個child子布局,這里可以放置想要過濾顏色的頁面;

最終我們就合成一張這樣帶濾鏡效果

追蹤源碼

我我們持續(xù)追蹤源碼到 RenderImage 類中,可以看到最終也是創(chuàng)建了一個 ColorFilter 。

class ColorFiltered extends SingleChildRenderObjectWidget {
  /// Creates a widget that applies a [ColorFilter] to its child.
  ///
  /// The [colorFilter] must not be null.
  const ColorFiltered({required this.colorFilter, Widget? child, Key? key})
      : assert(colorFilter != null),
        super(key: key, child: child);

  /// The color filter to apply to the child of this widget.
  final ColorFilter colorFilter;

  @override
  RenderObject createRenderObject(BuildContext context) => _ColorFilterRenderObject(colorFilter);

  @override
  void updateRenderObject(BuildContext context, RenderObject renderObject) {
    (renderObject as _ColorFilterRenderObject).colorFilter = colorFilter;
  }

  @override
  void debugFillProperties(DiagnosticPropertiesBuilder properties) {
    super.debugFillProperties(properties);
    properties.add(DiagnosticsProperty<ColorFilter>('colorFilter', colorFilter));
  }
}

設(shè)置前

image-20211213081150413

設(shè)置后

image-20211213081202975

功能就這樣實現(xiàn)了,功能簡單,意義不凡。

附:ColorFiltered還可以實現(xiàn)類似“濾鏡”效果,讓一張圖片和color進行融合:

Row(

      children: <Widget>[

        Expanded(

          child: Image.asset('images/1.png'),

        ),

        Expanded(

            child: ColorFiltered(

          colorFilter: ColorFilter.mode(Colors.pink[200], BlendMode.modulate),

          child: Image.asset('images/1.png'),

        ))

      ],

    )

總結(jié)

到此這篇關(guān)于Flutter將整個App變?yōu)榛疑奈恼戮徒榻B到這了,更多相關(guān)Flutter?App變?yōu)榛疑珒?nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論