Flutter將整個(gè)App變?yōu)榛疑暮?jiǎn)單實(shí)現(xiàn)方法
前言
為了讓更多的人永遠(yuǎn)記住12月13日,各大廠都在這一天將應(yīng)用變灰了。
那么接下來我們看一下Flutter是如何實(shí)現(xiàn)的。
Flutter中實(shí)現(xiàn)整個(gè)App變?yōu)榛疑?/h2>
在Flutter中實(shí)現(xiàn)整個(gè)App變?yōu)榛疑欠浅:?jiǎn)單的,
只需要在最外層的控件上包裹ColorFiltered,用法如下:
ColorFiltered(顏色過濾器)
看名字就知道是增加顏色濾鏡效果的,
ColorFiltered( colorFilter:ColorFilter.mode(Colors.grey, BlendMode.color), child: child, );
將上面代碼放到全局根widget下,即可設(shè)置全部頁(yè)面顏色變灰
通過colorFilter可設(shè)置某種顏色過濾,比如變灰設(shè)置灰色即可,以及顏色混合模式
ColorFiltered 小部件繼承SingleChildRenderObjectWidget,因此會(huì)提供一個(gè)child子布局,這里可以放置想要過濾顏色的頁(yè)面;
最終我們就合成一張這樣帶濾鏡效果
追蹤源碼
我我們持續(xù)追蹤源碼到 RenderImage
類中,可以看到最終也是創(chuàng)建了一個(gè) 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è)置前
設(shè)置后
功能就這樣實(shí)現(xiàn)了,功能簡(jiǎn)單,意義不凡。
附:ColorFiltered還可以實(shí)現(xiàn)類似“濾鏡”效果,讓一張圖片和color進(jìn)行融合:
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將整個(gè)App變?yōu)榛疑奈恼戮徒榻B到這了,更多相關(guān)Flutter?App變?yōu)榛疑珒?nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Android自定義View實(shí)現(xiàn)旋轉(zhuǎn)的圓形圖片
這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)旋轉(zhuǎn)的圓形圖片,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-01-01Android自定義控件之繼承ViewGroup創(chuàng)建新容器
這篇文章主要介紹了Android自定義控件之繼承ViewGroup創(chuàng)建新容器,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-12-12android仿音悅臺(tái)頁(yè)面交互效果實(shí)例代碼
這篇文章主要介紹了android 仿音悅臺(tái)頁(yè)面播放效果實(shí)例代碼,新版的音悅臺(tái) APP 播放頁(yè)面交互非常有意思,可以把播放器往下拖動(dòng),然后在底部懸浮一個(gè)小框,還可以左右拖動(dòng)。2017-01-01Flutter實(shí)現(xiàn)固定header底部滑動(dòng)頁(yè)效果示例
這篇文章主要為大家介紹了Flutter實(shí)現(xiàn)固定header底部滑動(dòng)頁(yè)效果示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-12-12Android實(shí)現(xiàn)橫豎屏切換的實(shí)例代碼
本篇文章主要介紹了Android實(shí)現(xiàn)橫豎屏切換的實(shí)例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-06-06Android實(shí)現(xiàn)手勢(shì)滑動(dòng)多點(diǎn)觸摸縮放平移圖片效果
這篇文章主要介紹了Android實(shí)現(xiàn)手勢(shì)滑動(dòng)多點(diǎn)觸摸縮放平移圖片效果,實(shí)現(xiàn)圖片支持多點(diǎn)觸控,自由的進(jìn)行縮放、平移的注意事項(xiàng),感興趣的小伙伴們可以參考一下2016-02-02