flutter實現(xiàn)磨砂玻璃效果實例詳解
flutter 中實現(xiàn)磨砂玻璃效果
磨砂玻璃效果是一個很酷的用戶界面概念,使我們的用戶界面看起來更有吸引力。它基本上是一個模糊的覆蓋與減少不透明度,以區(qū)分或減少某一觀點。這個功能看起來確實不錯,但是它會影響應(yīng)用程序的性能。
那么,讓我們看看如何在 Flutter 中實現(xiàn)磨砂玻璃效果。
編寫代碼
通過使用 BackdroFilter () widget 和 ImageFilter 類,可以非常容易地在 Flutter 中實現(xiàn)它。用于模糊圖像、 container 或許多其他 widget 。它可以在 iOS 和 android 上運行。它用于突出需要更多焦點的內(nèi)容,模糊需要較少焦點的內(nèi)容。
創(chuàng)建一個 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),
)),
),
),
),
),
],
),
);
}
}
輸出效果
注意: 我將這個 widget 塊堆疊在一個 Image 上方,以查看工作效果。我用 Flutter 的標志作為一個圖像。現(xiàn)在,我們可以看到我們的圖像模糊效果。

以上就是flutter實現(xiàn)磨砂玻璃效果實例詳解的詳細內(nèi)容,更多關(guān)于flutter 磨砂玻璃的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Android Walker登錄記住密碼頁面功能實現(xiàn)
這篇文章主要為大家詳細介紹了Android Walker登錄記住密碼頁面功能的實現(xiàn),具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-05-05
Android DragVideo實現(xiàn)播放視頻時任意拖拽的方法
這篇文章主要介紹了Android DragVideo實現(xiàn)播放視頻時任意拖拽的方法的相關(guān)資料,一種在播放視頻時,能夠拖拽的方案,需要的朋友可以參考下2016-12-12
封裝的android監(jiān)聽手指左右滑動屏幕的事件類分享
這篇文章主要介紹了封裝的android監(jiān)聽手指左右滑動屏幕的事件類分享,本文分別給出了簡單處理方法的代碼和封裝好的處理類代碼,需要的朋友可以參考下2015-05-05
RecyclerView+PagerSnapHelper實現(xiàn)抖音首頁翻頁的Viewpager效果
這篇文章主要為大家詳細介紹了RecyclerView+PagerSnapHelper實現(xiàn)抖音首頁翻頁的Viewpager效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-10-10

