flutter實(shí)現(xiàn)磨砂玻璃效果實(shí)例詳解
flutter 中實(shí)現(xiàn)磨砂玻璃效果
磨砂玻璃效果是一個(gè)很酷的用戶界面概念,使我們的用戶界面看起來更有吸引力。它基本上是一個(gè)模糊的覆蓋與減少不透明度,以區(qū)分或減少某一觀點(diǎn)。這個(gè)功能看起來確實(shí)不錯(cuò),但是它會(huì)影響應(yīng)用程序的性能。
那么,讓我們看看如何在 Flutter 中實(shí)現(xiàn)磨砂玻璃效果。
編寫代碼
通過使用 BackdroFilter () widget 和 ImageFilter 類,可以非常容易地在 Flutter 中實(shí)現(xiàn)它。用于模糊圖像、 container 或許多其他 widget 。它可以在 iOS 和 android 上運(yùn)行。它用于突出需要更多焦點(diǎn)的內(nèi)容,模糊需要較少焦點(diǎn)的內(nèi)容。
創(chuàng)建一個(gè) container 并使用 BackdroFilter 和 ClipRect 將其包裝起來?,F(xiàn)在添加背景濾鏡的屬性: ImageFilter.素,然后添加 sigmaX,sigmaY。SigmaX 和 sigmaY 越高,模糊度越高。
import 'dart:ui';
import 'package:flutter/material.dart';
class FrostedGlassLookDemo extends StatefulWidget {
const FrostedGlassLookDemo({super.key});
@override
@override_FrostedGlassLookDemoState
createState() => _FrostedGlassLookDemoState();
}
class _FrostedGlassLookDemoState extends State<FrostedGlassLookDemo> {
@override
@overrideWidget
build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
elevation: 1,
centerTitle: true,
title: const Text("Frosted Glass Look Demo"),
backgroundColor: Colors.blueGrey,
),
body: Stack(
children: [
Center(
child: Container(
height: MediaQuery.of(context).size.height / 3,
width: MediaQuery.of(context).size.width / 1,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
),
child: const FlutterLogo(),
)),
Center(
child: ClipRect(
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0),
child: Container(
height: MediaQuery.of(context).size.height / 3,
width: MediaQuery.of(context).size.width / 1.5,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
color: Colors.grey.shade200.withOpacity(0.5)),
child: const Center(
child: Text(
"Glass Effect Container",
style: TextStyle(fontSize: 15),
)),
),
),
),
),
],
),
);
}
}
輸出效果
注意: 我將這個(gè) widget 塊堆疊在一個(gè) Image 上方,以查看工作效果。我用 Flutter 的標(biāo)志作為一個(gè)圖像?,F(xiàn)在,我們可以看到我們的圖像模糊效果。

以上就是flutter實(shí)現(xiàn)磨砂玻璃效果實(shí)例詳解的詳細(xì)內(nèi)容,更多關(guān)于flutter 磨砂玻璃的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Android Vitamio和ExoPlayer兩種播放器優(yōu)劣分析
Vitamio和ExoPlayer都是用于安卓平臺(tái)的視頻播放器庫,它們各有優(yōu)缺點(diǎn),具體使用哪一個(gè),需要根據(jù)你的實(shí)際需求、開發(fā)經(jīng)驗(yàn)、項(xiàng)目規(guī)模等多個(gè)因素綜合考慮2023-04-04
Android實(shí)現(xiàn)通話最小化懸浮框效果
本片內(nèi)容給大家介紹了Android音視頻通話過程中最小化成懸浮框的實(shí)現(xiàn)的方法以及代碼寫法。2017-11-11
Android中微信搶紅包助手的實(shí)現(xiàn)詳解
本篇文章主要介紹了Android中微信搶紅包助手的實(shí)現(xiàn)詳解,通過利用AccessibilityService輔助服務(wù),監(jiān)測(cè)屏幕內(nèi)容,如監(jiān)聽狀態(tài)欄的信息,屏幕跳轉(zhuǎn)等,以此來實(shí)現(xiàn)自動(dòng)拆紅包的功能,有興趣的可以了解一下。2017-02-02
android將Bitmap對(duì)象保存到SD卡中的方法
這篇文章主要介紹了android將Bitmap對(duì)象保存到SD卡中的方法,涉及Android讀寫SD卡數(shù)據(jù)的方法,需要的朋友可以參考下2015-04-04
Android 進(jìn)度條自動(dòng)前進(jìn)效果的實(shí)現(xiàn)代碼
這篇文章主要介紹了Android 進(jìn)度條自動(dòng)前進(jìn)效果,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-07-07

