所以基本上我正在嘗試創建一個稍微不透明的容器。我正在使用該.withOpacity(...);方法,但是我沒有得到我想要的確切外觀。我想要的外觀是 Apple Music:
燈光模式:

黑暗模式:

它就像它不是不透明的,而是像玻璃,有霧的玻璃。
編輯:這是我到目前為止所擁有的:
Widget opaqueContainer(BuildContext context) {
final bool themeIsDark = true; // will use state manager here when implemented.
return Container(
height: 100,
width: 100,
color: themeIsDark ? Colors.black.withOpacity(0.7) : Colors.white.withOpacity(0.85),
child: IconButton(
onPressed: () {},
icon: const Icon(CupertinoIcons.phone, color: primary),
),
);
}
我可以創造這種顏色嗎?
謝謝!
uj5u.com熱心網友回復:
要創建上述效果,您需要將blur效果與所需顏色結合使用,該blur效果將為您提供霧狀玻璃的外觀和感覺。
在顫振中,您可以使用BackdropFilter如下所示的小部件來模糊小部件后面的區域。
import 'dart:ui' as ui;
// Use ClipRect to contain the effect to the child's size.
ClipRect(
child: BackdropFilter(
filter: ui.ImageFilter.blur(
sigmaX: 2.5,
sigmaY: 2.5,
),
child: Container(
height: 80,
width: 320,
color: themeIsDark
? Colors.black.withOpacity(0.7)
: Colors.white.withOpacity(0.85),
child: Center(
child: Text("Hello Word"),
),
),
),
);
這將為您提供類似于以下示例的輸出。

注意:這是一個顯示藍色效果的最小示例,而不是上述設計的再現
檔案
背景過濾器小部件
影像過濾器類
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/467958.html
上一篇:Flutter列布局
下一篇:Flutter-抽屜滑動區域擴大
