“磨砂玻璃"怎么做?Flutter 中的效果? [英] How do I do the "frosted glass" effect in Flutter?

查看:8
本文介绍了“磨砂玻璃"怎么做?Flutter 中的效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个 Flutter 应用程序,我想使用/实现 iOS 上常见的磨砂玻璃"效果.我该怎么做?

解决方案

你可以使用

import 'dart:ui';导入包:颤振/material.dart";无效的主要(){runApp(new MaterialApp(home: new FrostedDemo()));}FrostedDemo 类扩展 StatelessWidget {@覆盖小部件构建(BuildContext 上下文){返回新的脚手架(正文:新堆栈(孩子们:<小部件>[新的约束框(约束:const BoxConstraints.expand(),孩子:新的 FlutterLogo()),新中心(孩子:新剪辑矩形(孩子:新的背景过滤器(过滤器:新 ImageFilter.blur(sigmaX:10.0,sigmaY:10.0),孩子:新容器(宽度:200.0,高度:200.0,装饰:新盒子装饰(颜色:Colors.grey.shade200.withOpacity(0.5)),孩子:新中心(孩子:新文本('磨砂',风格:Theme.of(context).textTheme.display3),),),),),),],),);}}

I'm writing a Flutter app, and I'd like to use/implement the "frosted glass" effect that's common on iOS. How do I do this?

解决方案

You can use the BackdropFilter widget to achieve this effect.

import 'dart:ui';
import 'package:flutter/material.dart';

void main() {
  runApp(new MaterialApp(home: new FrostedDemo()));
}

class FrostedDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      body: new Stack(
        children: <Widget>[
          new ConstrainedBox(
            constraints: const BoxConstraints.expand(),
            child: new FlutterLogo()
          ),
          new Center(
            child: new ClipRect(
              child: new BackdropFilter(
                filter: new ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0),
                child: new Container(
                  width: 200.0,
                  height: 200.0,
                  decoration: new BoxDecoration(
                    color: Colors.grey.shade200.withOpacity(0.5)
                  ),
                  child: new Center(
                    child: new Text(
                      'Frosted',
                      style: Theme.of(context).textTheme.display3
                    ),
                  ),
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}

这篇关于“磨砂玻璃"怎么做?Flutter 中的效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆