如何在颤振中做“磨砂玻璃”效果?

问题描述:

我正在写一个Flutter应用程序,我想使用/实现iOS上常见的“毛玻璃”效果。我该怎么做呢?如何在颤振中做“磨砂玻璃”效果?

您可以使用BackdropFilter widget来实现此效果。

screenshot

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 
        ), 
       ), 
       ), 
      ), 
      ), 
     ), 
     ], 
    ), 
    ); 
    } 
} 
+0

我怎么会做磨砂效果的覆盖应用程序的整个宽度/高度? – Pieter

+1

您可以使用堆栈https://gist.github.com/collinjackson/321ee23b25e409d8747b623c97afa1d5 http://pasteboard.co/4ln6HDHWb.png –

+0

或者,如果您尝试使用磨砂玻璃效果作为对话框的模态屏障,您可以修改ModalBarrier的副本以包含BackdropFilter。 https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/widgets/modal_barrier.dart –